如何迭代到列表中的元组

Kir*_*ton 2 python iteration tuples list python-3.x

我正在编写一个程序,我在这样的列表中有一堆元组:

[('a01', '01-24-2011', 's1'), ('a03', '01-24-2011', 's2') 等等

元组是格式

(animal ID, date(month, day, year), station# )
Run Code Online (Sandbox Code Playgroud)

我不知道如何访问有关该月的信息.

我试过了:

months = []    
for item in list:
    for month in item:
        if month[0] not in months:
            months.append(month[0])
Run Code Online (Sandbox Code Playgroud)

我在python 3中工作.

ins*_*get 9

L = [('a01', '01-24-2011', 's1'), ('a03', '01-24-2011', 's2')]
for animal, date, station in L:
    month, day, year = date.split('-')
    print("animal ID {} in month {} at station {}".format(animal, month, station))
Run Code Online (Sandbox Code Playgroud)

输出:

animal ID a01 in month 01 at station s1
animal ID a03 in month 01 at station s2
Run Code Online (Sandbox Code Playgroud)