代码拉取完成,页面将自动刷新
同步操作将从 goodfeng/soft32 强制同步,此操作会覆盖自 Fork 仓库以来所做的任何修改,且无法恢复!!!
确定后同步将在后台操作,完成时将刷新页面,请耐心等待。
# coding:utf-8
'''
列表数据库
'''
# 使用列表list来表示数据
bob = ['陈小山',21,'男','22软件3+2']
sue = ['麦海丽',20,'女','22软件3+2']
# # 获取二人的姓名和年龄
# name = bob[0]
# age = bob[1]
# print(name,age)
# # 增加年龄
# bob[1]+=1
# print(bob)
# 构造数据库database,命名为people
people = [bob,sue]
for person in people:
print(person)
# 新增一个人的记录(record)
tom = ['陈彬',22,'男','22软件3+2']
people.append(tom)
# 获取平均年龄
ages = [person[1] for person in people]
print(ages)
import numpy as np
avg_ages = np.mean(ages)
print(avg_ages)
# 给字段(Field)加标签
NAME,AGE,GENDER,CLASSNAME = 0,1,2,3 # range(4)
# 获取花名册
namelist = [person[NAME] for person in people]
print(namelist)
# 让值与字段名成对出现,避免数据格式变化
bob = [
['NAME','陈小山'],
['AGE',21],
['GENDER','男'],
['CLASSNAME','22软件3+2']
]
sue = [
['NAME','麦海丽'],
['AGE',20],
['GENDER','女'],
['CLASSNAME','22软件3+2']
]
people = [bob,sue]
for filed,value in bob:
print(filed,value)
# 如何获取花名册
namelist = []
for person in people:
for filed,value in person:
if filed == 'NAME':
namelist.append(value)
break
print(namelist)
# 获取任意字段
def field(record,label):
for filed,value in record:
if filed == label:
return value
fileds = []
for person in people:
fileds.append(field(person,'AGE')) # person['AGE'] => 字典dict
print(fileds)
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。