Ways to store dictionaries in the python3-list

Source: Internet
Author: User
This article is mainly for you in detail the python3-list of the method of storage dictionary, the need for friends can refer to the following

# Auther:aaron fan# Example 1: #定义几个字典alien_0 = {"Color": "Green", "points": 5}alien_1 = {"Color": "Yellow", "points": 10}alien_2 = {"Color": "Red", "points": #把字典存入到列表aliens中aliens = [Alien_0, alien_1, Alien_2] #遍历这个列表for alien in Aliens:print (alien ) #示例2: #创建一个用于存储外星人的空列表aliens = [] #创建30个绿色的外星人for alien_number in range: New_alien = {"Color": "Green", ' Points ': 5, ' s Peed ': ' Slow '} aliens.append (New_alien) #显示前5个外星人for alien in Aliens[:5]: print (alien) print ("...") #显示一共创建了多少个外星人print ("Number of aliens:%d"% len (Aliens)) #示例3: #创建一个用于存储外星人的空列表aliens = [] #创建30个绿色的外星人for alien_number in range: New_alien = {"Co Lor ":" Green ", ' Points ': 5, ' speed ': ' Slow '} aliens.append (New_alien) for Alien in Aliens[0:3]: if alien[' color '] = = ' Gree N ': alien[' "color '] = ' yellow ' alien[' speed '] = ' Medium ' alien[' points '] = elif alien[' color '] = = ' Y Ellow ': alien[' color ' = ' red ' alien[' speed '] = ' fast ' alien[' points '] = 15# Show Top 5 aliens for alien in aliens[ : 5]: Print (alien) print ("...") 

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.