In my code I have for loop to a dict... and I get desired output as shown below..
dict = {"apple":5,"banana":3, "mangos":2}
columns = ('apple', 'banana','mangos')
for column in columns:
value = dict.get(column)
print column,value
Output:
apple 5
banana 3
mangos 2
But if my dict changes to
dict = {"apple":5,"Oranges":3, "mangos":2}
the same for loop would give me following output
columns = ('apple', 'banana','mangos')
for column in columns:
value = dict.get(column)
print column,value
I get following, which is expected
apple 5
banana None
mangos 2
Now the question is, is there a way I can set the column loop
columns = ('apple', 'banana','mangos')
so that the second value 'banana' could be either 'banana' or 'orange' ?
bananaif the dict containsbananasororangeif it containsorangeas keys.OrderedDictwould be the way to godict.get(column, dict.get('orange')), but I strongly suspect this is an XY problem. What are you trying to do?