Python3.3 Organization List (try it out)

Source: Internet
Author: User
Tags python list

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)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.