0

Dict and enumerator object

what are the different scenarios where we can use dictionary and enumerator?

18th May 2019, 6:11 PM
Sahil Rana
Sahil Rana - avatar
4 Réponses
+ 4
Sahil Rana, you can use the for syntax for *any* shape of iterable, you just have to model the primary elements of that iterable correctly! Let's say you have a list that looks like this: list_ = [(1, (2, 3)), (4, (5, 6))] The primary elements of the list look like this: a, (b, c) So you can write: for a, (b, c) in list_: print(a, b, c)
19th May 2019, 3:32 PM
HonFu
HonFu - avatar
+ 1
Why do you place dictionaries and enum in a comparison?
19th May 2019, 12:32 AM
HonFu
HonFu - avatar
0
you can enum over a dictionary to iterate over keys and/or their values. d = {"1st":"first", "2nd":"second", "3rd":"third"} for j in enumerate(d): print(j[1],d[j[1]]) 1st first 2nd second 3rd third
19th May 2019, 12:52 PM
Choe
Choe - avatar
0
HonFu ,i was asking due to the fact that both objects are accessed by (for i,j in object) where i is key and j is value ,isn’t it?
19th May 2019, 3:11 PM
Sahil Rana
Sahil Rana - avatar