2016-12-09 104 views
0

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

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]) 

的Python代码,我需要通过这样

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]) 
+1

[基本的Python循环(可能的重复http://stackoverflow.com/questions/25228806/basic-python -loop) –

回答

1

迭代你可以只是这样做:

for item in data: 
    self.do_something(item) 

看一看的documentation