《Programming Python》笔记

define list:

bob = ['Bob Smith', 42, 30000, 'software']
sue = ['Sue Jones', 45, 40000, 'music']
people = [bob, sue]

>>> pays = [person[2] for person in people] # collect all pay
>>> pays
[36000.0, 60000.0]
>>> pays = map((lambda x: x[2]), people) # ditto
>>> pays
[36000.0, 60000.0]
Field labels
>>> NAME, AGE, PAY = range(3) # [0, 1, 2]
>>> bob = ['Bob Smith', 42, 10000]
>>> bob[NAME]
'Bob Smith'
>>> PAY, bob[PAY]
(2, 10000)