I came across the following interesting construct:
assuming you have a list of lists as follows:
my_list = [[\'captain1\', \'foo1\', \'bar1\', \'foobar1\
Actually your observation doesn't require special ordering of the operation. The reason is that x.pop(0)
modifies the object x
. So whether you evaluate the value (x
) before or after the key (x.pop(0)
) doesn't matter in this case.
Anyway I don't think the python language specification prescribes a certain order of operations, which means that you should not rely on the order being any particular.
Actually the standard implementation happens to evaluate the value before it evaluates the key, but there's nowhere in the standard where this is stated. The only guarantee is that the key-value pairs are evaluating in iteration order and they are inserted in that order.