>>> L = [1, "term1", 3, "term2", 4, "term3", 5, "termN"]# Create an iterator>>> it = iter(L)# zip the iterator with itself>>> zip(it, it)[(1, 'term1'), (3, 'term2'), (4, 'term3'), (5, 'termN')]
您想一次将三个项目分组吗?
>>> zip(it, it, it)
您想一次分组N个项目吗?
# Create N copies of the same iteratorit = [iter(L)] * N# Unpack the copies of the iterator, and pass them as parameters to zip>>> zip(*it)



