zip
class zip(object)
| zip(iter1 [,iter2 [...]]) --> zip object
|
| Return a zip object whose .__next__() method returns a tuple where
| the i-th element comes from the i-th iterable argument. The .__next__()
| method continues until the shortest iterable in the argument sequence
| is exhausted and then it raises StopIteration.
|
| Methods defined here:
|
| __getattribute__(self, name, /)
| Return getattr(self, name).
|
| __iter__(self, /)
| Implement iter(self).
|
| __new__(*args, **kwargs) from builtins.type
| Create and return a new object. See help(type) for accurate signature.
|
| __next__(self, /)
| Implement next(self).
|
| __reduce__(...)
| Return state information for pickling.
示例:
abc = [x for x in ["a", "b", "c"]] num = [x for x in range(1, 4)] zip_obj = zip(abc, num) print(zip_obj.__next__()) print(zip_obj.__next__()) print(zip_obj.__next__()) >>> ('a', 1) ('b', 2) ('c', 3) print(set(zip(abc, num))) >>> {('c', 3), ('a', 1), ('b', 2)} print(dict(zip(abc, num))) >>> {'a': 1, 'b': 2, 'c': 3} print(list(zip(abc, num))) >>> [('a', 1), ('b', 2), ('c', 3)] print(tuple(zip(abc, num))) >>> (('a', 1), ('b', 2), ('c', 3))