在python中使用record, for ** in **以及定义函数
来源:互联网 发布:2016nba总决赛数据统计 编辑:程序博客网 时间:2024/05/23 19:37
#! /usr/bin/env python
#coding=utf-8
bob = [['name', 'Bob Smith'], ['age', 42], ['pay', 10000]]
sue = [['name', 'Sue Jones'], ['age', 45], ['pay', 20000]]
people = [bob, sue]
for person in people:
print(person[0][1], person[2][1]) # name, pay
print([person[0][1] for person in people])
for person in people:
print(person[0][1].split()[-1]) # get last names
person[2][1] *= 1.10 # give a 10% raise
for person in people:
print(person[2])
for person in people:
for (name, value) in person:
if name == 'name': print(value) # find a specific field
print("\n")
##定义函数, record表示记录
def field(record, label):
for (fname, fvalue) in record:
if fname == label: # find any field by name
return fvalue
print(field(bob, 'name'))
print(field(sue, 'pay'))
for rec in people:
print(field(rec, 'age')) # print all ages
#coding=utf-8
bob = [['name', 'Bob Smith'], ['age', 42], ['pay', 10000]]
sue = [['name', 'Sue Jones'], ['age', 45], ['pay', 20000]]
people = [bob, sue]
for person in people:
print(person[0][1], person[2][1]) # name, pay
print([person[0][1] for person in people])
for person in people:
print(person[0][1].split()[-1]) # get last names
person[2][1] *= 1.10 # give a 10% raise
for person in people:
print(person[2])
for person in people:
for (name, value) in person:
if name == 'name': print(value) # find a specific field
print("\n")
##定义函数, record表示记录
def field(record, label):
for (fname, fvalue) in record:
if fname == label: # find any field by name
return fvalue
print(field(bob, 'name'))
print(field(sue, 'pay'))
for rec in people:
print(field(rec, 'age')) # print all ages
- 在python中使用record, for ** in **以及定义函数
- python中for in中定义多个参数
- for record in file
- JavaScript中函数的定义以及使用
- Python中函数的定义以及形参实参小结
- Python 函数定义,使用
- python 3.0 在for中使用insert
- Python 函数定义以及参数传递
- 在Delphi中使用三层结构ClientDataSet出现 Unable to find record or record ...
- python 函数定义和内置函数isinstance以及数据类型检查type的使用
- Octave教程五:控制语句if/while/for以及函数的定义和使用
- javascript中关键字in以及循环for...in的使用和注意事项
- 在c语言中函数的定义与使用
- 第6章创建函数-----------(在.bashrc文件中定义函数、在命令行创建函数、在命令行中使用函数)
- python第12篇之-函数的嵌套定义以及关键字nonlocal使用
- liunx 中 for in使用
- python else在for、while、try 语句中使用
- Python定义函数,模块导入以及Python主程序文件结构
- 常见Java框架
- C程序设计笔记——导言
- html
- Couldn't register com.X.XX with the bootstrap server. Error: unknown error code. 错误
- spring 实现aop的三种方法
- 在python中使用record, for ** in **以及定义函数
- html
- “cp: 略过目录”及“Could not locate Gemfile”错误的解决
- .NET连接SAP系统专题:NCO3调用BAPI的一些说明(六)
- 23种设计模式
- “21天教你学会C++”[来自CoolShell]
- html
- fread函数 和 feof函数
- Nutch 1.3 学习笔记3-1 Inject CrawlDB Reader