Python Forum
# only print cities that names start "Q" or earlier
Thread Rating:
  • 1 Vote(s) - 2 Average
  • 1
  • 2
  • 3
  • 4
  • 5
# only print cities that names start "Q" or earlier
#3
you can use also

from string import ascii_uppercase

visited_cities = ["New York", "Shanghai", "Munich", "Toyko", "Dubai", "Mexico City", "São Paulo", "Hyderabad","Qatar"]
new_cities = [city for city in visited_cities if city.startswith(tuple(ascii_uppercase[:17]))]
new_cities.sort()
print(new_cities)
Reply


Messages In This Thread
RE: # only print cities that names start "Q" or earlier - by buran - Jul-17-2017, 07:23 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Start print a text after open an async task via button Nietzsche 0 810 May-15-2023, 06:52 AM
Last Post: Nietzsche
  Print names in x-axis of a time-series values hobbyist 4 1,405 Apr-22-2023, 09:29 PM
Last Post: deanhystad
  2 versions of module installed, how to import the earlier one sveto4ka 8 5,265 Oct-22-2019, 02:51 PM
Last Post: snippsat
  What's the difference b/w assigning start=None and start=" " Madara 1 2,437 Aug-06-2018, 08:23 AM
Last Post: buran
  How to print the names of assignments if they are randomly selected Kongurinn 2 3,497 Oct-22-2017, 07:31 AM
Last Post: buran

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020