python3-How to store dictionaries in lists
This article mainly introduces in detail the relevant information about the method of storing dictionaries in python3-list. Friends in need can refer to it
# Auther: Aaron Fan #示例1: #定义几个字典 alien_0 = {"color":"green", "points":5} alien_1 = {"color":"yellow", "points":10} alien_2 = {"color":"red", "points":15} #把字典存入到列表aliens中 aliens = [alien_0, alien_1, alien_2] #遍历这个列表 for alien in aliens: print(alien) #示例2: #创建一个用于存储外星人的空列表 aliens = [] #创建30个绿色的外星人 for alien_number in range(30): new_alien = {"color":"green", 'points':5, 'speed':'slow'} aliens.append(new_alien) #显示前5个外星人 for alien in aliens[:5]: print(alien) print("...") #显示一共创建了多少个外星人 print("外星人的数量是: %d" % len(aliens)) #示例3: #创建一个用于存储外星人的空列表 aliens = [] #创建30个绿色的外星人 for alien_number in range(30): new_alien = {"color":"green", 'points':5, 'speed':'slow'} aliens.append(new_alien) for alien in aliens[0:3]: if alien['color'] == 'green': alien['color'] = 'yellow' alien['speed'] = 'medium' alien['points'] = 10 elif alien['color'] == 'yellow': alien['color'] = 'red' alien['speed'] = 'fast' alien['points'] = 15 #显示前5个外星人 for alien in aliens[:5]: print(alien) print("...")
The above is the detailed content of python3-How to store dictionaries in lists. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



Solution to permission issues when viewing Python version in Linux terminal When you try to view Python version in Linux terminal, enter python...

When using Python's pandas library, how to copy whole columns between two DataFrames with different structures is a common problem. Suppose we have two Dats...

How to teach computer novice programming basics within 10 hours? If you only have 10 hours to teach computer novice some programming knowledge, what would you choose to teach...

How to avoid being detected when using FiddlerEverywhere for man-in-the-middle readings When you use FiddlerEverywhere...

How does Uvicorn continuously listen for HTTP requests? Uvicorn is a lightweight web server based on ASGI. One of its core functions is to listen for HTTP requests and proceed...

The article discusses popular Python libraries like NumPy, Pandas, Matplotlib, Scikit-learn, TensorFlow, Django, Flask, and Requests, detailing their uses in scientific computing, data analysis, visualization, machine learning, web development, and H

In Python, how to dynamically create an object through a string and call its methods? This is a common programming requirement, especially if it needs to be configured or run...

Using python in Linux terminal...
