Zip List In Python

Share:

Zip List 💪 




What Is Zip List In Python?

Python's zip() function is defined as zip(*iterables) . The function takes in iterables as arguments and returns an iterator. This iterator generates a series of tuples containing elements from each iterable. zip() can accept any type of iterable, such as files, lists, tuples, dictionaries, sets, and so on.

What is the Uses Of Zip List In Python?

Python's zip() function creates an iterator that will aggregate elements from two or more iterables. You can use the resulting iterator to quickly and consistently solve common programming problems, like creating dictionaries


Code Of Zip List Function:

# print name And Subject

my_strings = 'Ali  MATH' ,'Ali  PHYSICS' ,'Ali  chemistry'

#print Scores

my_numbers = 85,25,64

#Zip list Both Variables

results = list(zip(my_strings,my_numbers))

print(results)

OUTPUT:

[('Ali MATH', 85), ('Ali PHYSICS', 25), ('Ali chemistry', 64)]