Write Insert(Place) and Delete(Place) methods in python to add Place and
Remove Place considering them to act as Insert and Delete operations on a List
storing names of cities. Also print the details after every operation in the
ascending order
Answers
Answered by
1
def Insert(place, places):
places += [place]
def Delete(place, places):
places[:] = [item for item in places if item != place]
places = []
cities = ["Panjim", "Margao", "Mapusa", "Quepem"]
for place in cities:
Insert(place, places)
print(f"Added '{place}' in places!")
print("Added places", places, "\n")
for place in cities:
Delete(place, places)
print(f"Removed '{place}' from places!")
print("After removing:", places)
Similar questions