Answer to Question #193086 in Python for FORTUNE AIDOO

Question #193086

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-05-13T18:09:52-0400
string = 'cat dog Mike kite Messi'

new_string = string.split(' ')

# delete three words
del new_string[1]
new_string.remove('cat')
new_string.pop(0)

# sorting
new_string.sort()

# Add new words
new_string.append('pop')
new_string.insert(0, 'dog')
new_string.extend(['ff', 'hh'])

# turn the list of words back into a single string using join
new_string = ' '.join(new_string)
print(new_string)

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