14.5k views
24 votes
CODING TIME

1. Create a list of your favorite food items. (at least 7 elements). With the help of coding, illustrate the working of extend, append and insert functions.
2. Show the difference between remove and pop on a list of flowers.

1 Answer

8 votes

Answer:

Kindly check explanation

Step-by-step explanation:

food = ['rice', 'beans','yam', 'bread', 'pasta', 'cocoa','tea']

add = ['plantain']

new_list = food + one_more

print(new_list)

Output: ['rice', 'beans','yam', 'bread', 'pasta', 'cocoa','tea','plantain']

food.append('flour')

print(food)

Output : ['rice', 'beans','yam', 'bread', 'pasta', 'cocoa','tea','flour']

food.insert(0,'milk')

Output: ['milk','rice', 'beans','yam', 'bread', 'pasta', 'cocoa','tea']

flowers = ['tulip', 'lavender', 'carnation']

To remove carnation from list

flowers.remove('carnation')

Output : ['lavender', 'carnation']

To remove carnation using pop()

flowers.pop(2)

User Jessica Alan
by
5.5k points