3-8 World:Come up with at least 5 places you want to travel.
- Store these places in a list and make sure that the elements are not in alphabetical order.
places = [' Beijing ', ' Xizang ', ' Yunnan ', ' Chongqing ', ' Qinghai ']
- Prints the list in its original order. Do not consider the problem of neat output, just print the original Python list.
Print (places)
- Use sorted () to print this list in alphabetical order, without modifying it.
Print (sorted (places))
- Print the list again and verify that the order is not changed.
Print (places)
- Use sorted () to print this list in reverse alphabetical order, without modifying it.
Print (sorted (places,reverse=true))
- Print the list again and verify that the order is not changed.
Print (places)
- Use reverse () to modify the order in which the list elements are arranged. Print the list and verify that the sorting order has changed.
Places.reverse ()
Print (places)
- Use reverse () to modify the order in which the list elements are arranged again. Print the list and verify that it has been restored to its original order.
Places.reverse ()
Print (places)
- Use sort () to modify the list so that its elements are sorted alphabetically. Print the list and verify that the sorting order has changed.
Places.sort ()
Print (places)
- Use sort () to modify the list so that its elements are sorted in the opposite order of alphabetical order. Print the list and verify that the sorting order has changed.
Places.sort (Reverse=true)
Print (places)
3-9 Dinner guests: in one of the programs written during the practice 3-4~3-7 exercise, use Len () to print a message stating how many guests you have invited to dinner with you.
guest_names=[' Guo ', ' Huang ', ' Jia ', ' Mei ']
Message = "I invited" + str (len (my_favorite_fruit)) + "guests for dinner together."
Print (message)
3-10 try each function: think of something that can be stored in a list, such as mountains, rivers, countries, cities, languages, or anything you like. Write a program in which you create a list that contains these elements, and then work with the list at least once for each function described in this chapter.
my_favorite_fruit= ["Mango", "lychee", "orange")
Print (sorted (my_favorite_fruit)) #按字母顺序进行临时排序
My_favorite_fruit.sort () #按字母顺序进行永久排序
Print (My_favorite_fruit)
My_favorite_fruit.reverse () #按相反的顺序打印
Print (My_favorite_fruit)
Message= "The length of the list is" + str (len (my_favorite_fruit)) + "." #打印列表长度
Print (Message)
Python3.3 Organization List (try it out)