打印所有邮票:
stamps = [
['10:09:56.033', 'ComponentB', 2, 'DEBUG', 'description'],
['10:09:56.034', 'ComponentB', 1, 'DEBUG,description'],
['10:09:57.034', 'ComponentB', 2, 'DEBUG,description'],
['10:09:57.045', 'ComponentB', 2, 'DEBUG,description']
]
for var in stamps:
print var[0]
至于每秒打印一次(hcwhsa 答案的变体,使用 lambdas 而不是一起使用单独的函数):
from itertools import groupby
lis = [['10:09:56.033', 'ComponentB', 2, 'DEBUG', 'description'],
['10:09:56.034', 'ComponentB', 1, 'DEBUG', 'description'],
['10:09:57.034', 'ComponentB', 2, 'DEBUG', 'description'],
['10:09:57.045', 'ComponentB', 2, 'DEBUG', 'description']]
for k, g in groupby(lis, key=lambda item: item[0][0:8]):
print k
print '\n'.join(x[0] for x in g) + '\n'
这应该更快。