0
Dict and enumerator object
what are the different scenarios where we can use dictionary and enumerator?
4 Answers
+ 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)
+ 1
Why do you place dictionaries and enum in a comparison?
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
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?