Hacker News new | past | comments | ask | show | jobs | submit login

That's not even valid Python.



Well,

  [k for k in OrderedDict(a=1, b=2)]
not that different in valid Python


But as pointed out elsewhere, kwargs aren't guaranteed to be in order, so by the time the OrderedDict is built it's already wrong. It seems the change we're discussing was primarily motivated by a desire to fix that specific problem.


The point OP is making is that none of these statements will guarantee the order of insertion, since OrderedDict must take the variadic kwargs input as a dict, which is inherently unordered. You have to use a list of tuples.


Yes, agree, just wanted to give the correct Python for the (still) ill attempt at traversing OrderedDict keys in order.




Consider applying for YC's W25 batch! Applications are open till Nov 12.

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: