+ 1

Priting value on a for loop

Greeting everyone, I have this code that I try to figure out its output list1 = ['ID 'name', 'email', 'tel'] list2 = ['12345678', 'Joe', joe@mail.com] combination = list(zip(list1, list2)) print(combination) dictCombo = {} for key,value in combination:  print(key) print(value) dictCombo[key] = value print(dictCombol'name'l) print(dictCombo) My understanding so far that print(key) will print every element on the combination list, but what's the value of the variable "value" and why it's Joe?

24th Mar 2022, 9:18 AM
Fatimah Mohammad Emad EL Den
1 Odpowiedź
+ 2
Fatimah Mohammad , there are some issues in the code (missing quotes, missing phone number in list2, in this case the shortest iterable defines the number of key:value pairs) we do not need to create a list and then use this for creating the dict, we can go directly from zip() to the dict. maybe this can help you: list1 = ['ID', 'name', 'email', 'tel'] list2 = ['12345678', 'Joe', 'joe@mail.com'] dictCombo = dict(zip(list1, list2)) print(dictCombo) for key,value in dictCombo.items(): print(key,":") print(value)
24th Mar 2022, 11:53 AM
Lothar
Lothar - avatar