+ 1
format and dict question
d = {10:"x", 1:"wx", 2:"yz"} a = d.setdefault(1) b = d.setdefault(3) s = "{}" * len(d) print(s.format(*d)) Why will the output always be 11032?
4 Respuestas
+ 2
because you are printing the keys inside d
row 2 moves key 1 to the front
row 3 tries to call for key 3 which doesn't exists so it adds 3: None in
so dict will be
{1:"wx", 10:"x", 3:None, 2:"yz"}
keys printed
11032
what are you trying to accomplish, want help?
+ 1
thanks very much for answering me, but why does row 2 move key 1 to the front? and why dose key 3 insert between 10 and 2?
0
i dont know to say whitout testing but i also think that the way you are formatting that thing suffles it around abit
0
depending on what you are trying to accomplish you might want to change the code a bit