Ham*_*udy 0 python arrays list raspberry-pi
我将以下数据存储为col?
Location
47.608941, -122.340145
55,66
33,22
55,22
Run Code Online (Sandbox Code Playgroud)
如何忽略第一行并在Python中打印出其余部分?
for index in range(len(col)):
print col[index]
Run Code Online (Sandbox Code Playgroud)
你可以从索引1开始:
for index in range(1, len(col)):
print col[index]
Run Code Online (Sandbox Code Playgroud)
但这不是那个惯用语.直接在列表上切片和循环更是如此:
for column in col[1:]:
print column
Run Code Online (Sandbox Code Playgroud)
如果列表很大,您可以显式创建隐式循环迭代器:
it = iter(col)
next(it, None) # skip first entry
for column in it:
print column
Run Code Online (Sandbox Code Playgroud)
或用于itertools.islice()跳过项目:
from itertools import islice
for column in islice(col, 1, None):
print column
Run Code Online (Sandbox Code Playgroud)