作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在编写一个程序,其中我在这样的列表中有一堆元组:
[('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 中工作。
最佳答案
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))
输出:
animal ID a01 in month 01 at station s1
animal ID a03 in month 01 at station s2
关于python - 如何将列表迭代到元组中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27081463/
我是一名优秀的程序员,十分优秀!