DEV Community

Discussion on: What is a Zip function in Python?

Collapse
 
waylonwalker profile image
Waylon Walker

🤯 This example kinda blow my mind. I love *unpacking, but have never used it inside of zip.

src = [(1001, 'apple'), (1002, 'orange'), (1003, 'banana')]    
ids, items = tuple(zip(*src))
print(ids)      # (1001, 1002, 1003)
print(items)   # ('apple', 'orange', 'banana')