Answer to Question #248589 in Python for Raymond Ekwubiri

Question #248589
Part 1

Write a Python program that does the following.

Create a string that is a long series of words separated by spaces. The string is your own creative choice. It can be names, favorite foods, animals, anything. Just make it up yourself. Do not copy the string from another source.

Turn the string into a list of words using split.

Delete three words from the list, but delete each one using a different kind of Python operation.

Sort the list.

Add new words to the list (three or more) using three different kinds of Python operation.

Turn the list of words back into a single string using join.

Print the string.
1
Expert's answer
2021-10-08T07:14:49-0400
words = 'Create a string that is a long series of words separated by spaces can be names, favorite foods, animals, anything'


#Turn the string into a list of words using split.
words = words.split()


#Delete 3 words
words.remove('Create')
words.pop(-1)
del words[1]


#Sort elements
words.sort()


#Add elements
words.append('first')
words.insert(4,'second')
words.extend(['third', 'forth'])


#List to string
final_sentence = ' '.join(words)
print(final_sentence)

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS