Function | Description | Ref |
---|---|---|
all() | Return true if all items in an iterable are true | |
zip() | Returns an iterator, from two or more iterators |
zip()
The zip()
function returns a zip
object, which is an iterator of tuples where the first item in each passed iterator is paired together, and then the second item in each passed iterator are paired together etc.
If the passed iterables have different lengths, the iterable with the least items decides the length of the new iterator.
a = ("John", "Charles", "Mike")
b = ("Jenny", "Christy", "Monica")
x = zip(a, b)
# Use the tuple() function to display a readable version of the result:
print(tuple(x))
print(type(x))
(('John', 'Jenny'), ('Charles', 'Christy'), ('Mike', 'Monica'))
<class 'zip'>
Back to parent page: Python