Python zip function

8 Views
Published
python zip function tutorial example explained

#python #zip #function

# zip(*iterables) = aggregate elements from two or more iterables (list, tuples, sets, etc.)
# creates a zip object with paired elements stored in tuples for each element

usernames = ["Dude", "Bro", "Mister"]
passwords = ("p@ssword", "abc123", "guest")
login_dates = ["1/1/2021","1/2/2021","1/3/2021"]

# --------------------------------------
users = list(zip(usernames,passwords))

for i in users:
print(i)

# --------------------------------------
users = dict(zip(usernames,passwords))

for key,value in users.items():
print(key+" : "+value)

# --------------------------------------
users = zip(usernames,passwords,login_dates)

for i in users:
print(i)

# --------------------------------------
Category
Bro Code
Tags
python, zip(), python zip function
Be the first to comment