Answer to Question #169102 in Python for Hanson Dartey

Question #169102

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. 
1
Expert's answer
2021-03-05T05:14:55-0500
string = 'dog cat bird mouse cow horse hen tiger elephant dolphin snake giraffe lion lynx rhino'
L = string.split()

print('Original list:')
print(L, '\n')

print('Popping the last element:')
L.pop()
print(L, '\n')

print('Delating 3th element:')
del L[2]
print(L, '\n')

print("Removing 'elephant':")
L.remove('elephant')
print(L, '\n')

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