+ 2

Ambiguous python quiz

I was trying to answer this python quiz d = {10: "x", 1:"wx", 2:"yz"} a = d.setdefault(1) b = d.setdefault(3) s = '{}'*len(d) print(s.format(*d)) The answer is 10132. But it depends on the ordering of inserted key in the dictionary. According to the following stack overflow answer the order of insertion of a key in an unordered dictionary is implementation dependent. what's your thoughts? https://stackoverflow.com/questions/5629023/key-order-in-python-dictionaries

26th Feb 2018, 10:50 AM
Ravi Chandra Enaganti
Ravi Chandra Enaganti - avatar
1 Réponse
+ 1
I agree with you. The answer is questionnable as dictionary elements have no guaranteed order.
3rd Apr 2018, 10:06 AM
Loïc Mahé
Loïc Mahé - avatar