Part 1
Write a Python program that does the following.
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)
Comments
Leave a comment