我寫一個程序,我有這樣一個名單一堆的元組:如何迭代到列表到一個元組
[('a01', '01-24-2011', 's1'), ('a03', '01-24-2011', 's2')
等
元組的格式爲
(animal ID, date(month, day, year), station#)
我不知道如何訪問有關月份的信息。
我曾嘗試:
months = []
for item in list:
for month in item:
if month[0] not in months:
months.append(month[0])
我在Python工作3
downvote的任何原因? – Hackaholic 2014-11-23 01:49:58
我發現gg.kaspersky提出的列表理解比map/lambda更好:[item [1] .split(' - ')[0] for my_list] – 2014-11-27 11:16:06