Problem Statement:
We are given a sentence, we need to word mix in Python means we need to mix the words of the sentence such that new words get formed. How? We need to select a letter from each word from the same index. If there is no letter in the word, do nothing and proceed further.
For example, sentence=> “Welcome to CopyAssignment”=> WtC eoo lp cy oA ms es i g n m e n t
Code for Word Mix in Python:
sentence = 'Welcome to CopyAssignment'
words = sentence.split()
max_len_list = max(words, key = len)
max_len = len(max_len_list)
new_words=[]
for i in range(max_len): # for looping max word length times
new_word=[]
for j in range(len(words)): # for looping numbers of words time
try:
new_word.append(words[j][i])
except:
pass
new_words.append(new_word)
word_list=[]
for i in new_words:
word_list.append(''.join(i))
for i in word_list:
print(i, end=" ")
Output:

Explanation:
We have accessed the letters of each word of the sentence, but not all words do not have the same numbers of letters that are why we have used the try and except block of Python. It saved us from throwing error even when we are accessing a string index that does not exist. We hope you find your solution to Word Mix in Python.
Also Read:
- Hyphenate Letters in Python
- Earthquake in Python | Easy Calculation
- Striped Rectangle in Python
- Perpendicular Words in Python
- Composite Number in Python
- Greatest Among Four Numbers in Python
- Reverse the sentence in Python
- Denominations in Python
- Min and max values in an array in JavaScript
- Keyboard events in JavaScript
- Reaching Ground Floor in Python
- Number of Moves in Python
- Starks Adventure in Python
- Neutralization in Python | Assignment Expert
- Free shipping in Python
- Raj has ordered two electronic items Python | Assignment Expert
- First Place in Python
- Triples with Properties in Python
- Nested list Indexing Python
- Team Points in Python
- Two words combination in Python
- ID Card in Python
- Cipher with a key in Python | Assignment Expert
- Multiple of 5 in Python
- Sandglass Star in Python
- Multiple of 3 in Python | Assignment Expert
- Ticket selling in Cricket Stadium using Python | Assignment Expert
- Sum of List Elements in Python
- All possible subsets in Python
- Names and Nicknames in Python