[Tutor] looping over a dictionary with tuple of 2 elements as value

Manprit Singh manpritsinghece at gmail.com
Sun Jul 19 06:55:48 EDT 2020


Dear all,
Consider a dictionary as given below :
a = {"A" : (3, 1),  "B" : (4, 9)}
Here in this dictionary for key "A" the value is tuple (3, 1), and for key
"B" the value is tuple (4, 9) . Now for looping over this dictionary to get
an output like this :
A 3 1
B 4 9

for i, (j, k) in a.items( ):
    print(i,  j,  k)

Is this for loop syntactically correct ?

Regards
Manprit Singh


More information about the Tutor mailing list