繁体   English   中英

for循环列表内的列表

[英]for loop for lists inside of a list

我是python的新手。 我有一个列表列表,需要遍历它们或编写一个简单的for循环(在下面的示例中,“数据”中有6个列表,但是我并不总是要知道有多少个列表,所以我只需要迭代一下到最后)。 我有下面的python代码

data=[['2', '33494.45', '91.415838', '0'], ['2', '33994.3', '101.1738', '0'], ['2','34494.15', '107.04941', '0'], ['2', '34994', '107.67817', '0'], ['2', '35493.85', '107.26302', '0'], ['2', '35500', '107.21114', '0'], ['2', '35993.7', '103.04895', '0']]

self.do_something(data[i])

我需要迭代这样

self.do_something(data[0])
self.do_something(data[1])
self.do_something(data[2])
self.do_something(data[3])
self.do_something(data[4])
self.do_something(data[5])
self.do_something(data[6])

您可以这样做:

for item in data:
    self.do_something(item)

看一下文档

采用:

map(self.do_something, data)

在此处阅读有关此内容的更多信息: http : //book.pythontips.com/en/latest/map_filter.html

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM