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.
my_words = 'car cat red dog chair parking money pillow picture turtle ' \
'KFC bottle sheep chicken marten bear read comp phone mouse horse'
# creating a list of words
listing = my_words.split()
# deleting items from the list
listing.remove('dog')
listing.pop(-1)
del listing[1]
# sorting made list
listing.sort()
# adding elements or words to our list
listing.append('computer')
listing.insert(5,'milano')
listing.extend(['Rio', 'China'])
# list is to string
final_words = ' '.join(listing)
print(final_words)
Comments
good work
Leave a comment