+ 1
There is a dictionary called pairs. How to use get() to print the third element in "orange"?
pairs = {1: "apple", "orange": [2, 3, 4], True: False, 12: "True", }
2 Respostas
+ 4
You can try this
print( pairs.get( "orange" )[2] )
BUT I have to warn you, since the dict item value here is an iterable( a `list`), it is important to have a valid index to be uaed for refering any of its items.
So a safer way would be to check whether the index was within the range of the iterable's length, before proceeding with using the index to obtain an item from the iterable (dict item value).
+ 1
Thank you Ipang