Python Programming: Manipulating Lists for Travel Destinations
- "List 10 places:"\nplaces = "["Paris", "Tokyo", "New York City", "Rome", "Barcelona", "Sydney", "Cape Town", "Rio de Janeiro", "Bali", "Amsterdam"]"\n\n2) "Reverse the list of places:"\nreverse_places = list(reversed(places))\n\n3) "Sort the list of places in ascending order:"\nsorted_places = sorted(places)\n\n4) "Sort the list of places in descending order:"\nreverse_sorted_places = sorted(places, reverse=True)\n\n5) "Insert "Antarctic" at the beginning and "Arctic Sea" at the end:"\nplaces.insert(0, "Antarctic")\nplaces.append("Arctic Sea")\n\n6) "Insert "Chicago" at the middle of the list:"\nplaces.insert(len(places)//2, "Chicago")\n\n7) "Delete the 3rd and 9th elements:"\ndel places[2]\ndel places[8]
原文地址: https://www.cveoy.top/t/topic/pntV 著作权归作者所有。请勿转载和采集!