Mar-05-2018, 03:57 PM
hi, im new to coding hence i have a rather simple problem!
im trying to sort a list of cities, so that for cities that start with a letter greater than Q, the city name is removed from the list.
My code runs but i dont seem to get the correct output.
How can i specify startswith greater than Q?
many thanks for your help.
im trying to sort a list of cities, so that for cities that start with a letter greater than Q, the city name is removed from the list.
My code runs but i dont seem to get the correct output.
How can i specify startswith greater than Q?
many thanks for your help.
visited_cities = ["New York", "Shanghai", "Munich", "Toyko", "Dubai", "Mexico City", "São Paulo", "Hyderabad"] sorted_cities=sorted(visited_cities) print(sorted_cities) for x in sorted_cities: if x>="Q": sorted_cities.remove(x) else: pass print(sorted_cities)