Answer to Question #282093 in Python for kika

Question #282093

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. 
  • 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-12-23T11:10:25-0500
my_string = "cat dog sheep goat tiger lion goose duck bird anything whatever test string"
my_string_list = my_string.split()
my_string_list.pop()
my_string_list.remove("whatever")
del my_string_list[0]
my_string_list.sort()
my_string_list.append("cat")
my_string_list.extend(["string"])
my_string_list.insert(0, "whatever")
my_string = " ".join(my_string_list)
print(my_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