python unzip list 1

python unzip list

zipped = [("a", 1), ("b", 2)]
unzipped_object = zip(*zipped)
unzipped_list = list(unzipped_object)

# Output:
# [('a', 'b'), (1, 2)]

Here is what the above code is Doing:
1. We create a list of tuples called zipped.
2. We use the zip() function to unzip the zipped list.
3. We convert the unzipped object into a list.
4. We print the unzipped list.

The output shows that the zip() function has unzipped the list.

Similar Posts