python list

葫芦的运维日志

下一篇 搜索 上一篇

2018/09/08 21:51


>>> bob=['Bob Smith',42,30000,'software']
>>> sue=['Sue Jones',45,40000,'hardware']
>>> bob[0],sue[2]
('Bob Smith', 40000)
>>> bob[0].split()[-1]
'Smith'
>>> sue[2]*=1.25
>>> sue
['Sue Jones', 45, 50000.0, 'hardware']
>>> people=[bob,sue]
>>> for person in people:
...     print(person)
...
['Bob Smith', 42, 30000, 'software']
['Sue Jones', 45, 50000.0, 'hardware']
>>> people[1][0]
'Sue Jones'
>>> for person in people:
...     print(person[0].split()[-1])
...     person[2]*=1.20
...
Smith
Jones
>>> for person in people: print(person[2])
...
36000.0
60000.0
>>> pays=[person[2] for person in people]
>>> pays
[36000.0, 60000.0]
>>> pays=map((lambda x :x[2]),people)
>>> type(pays)
<type 'list'>
>>> pays
[36000.0, 60000.0]
>>> sum(person[2] for person in people)
96000.0
>>> people.append(['Tom',50,0,None])
>>> len(people)
3
>>> people[-1][0]
'Tom'

 

葫芦的运维日志

打赏

上一篇 搜索 下一篇
© 冰糖葫芦甜(bthlt.com) 2019 王梓 打赏联系方式 陕ICP备17005322号