Conversation

Notices

  1. Python 3.6 dictionaries are order-preserving. I'm just wondering why there's no way to access dictionary items by index directly. When dictionary retains order, I would love to see it to be accessible just like a list. It would be quite logical.
    of course you can get keys() from dict, or items(), but I would think that's inefficient way, if I know I want to access 5th item in dictionary.
    # # # # # # !python

    Sunday, 25-Dec-16 10:18:42 UTC from loadaverage.org
    1. Here's some continuation to the thoughts of the original post. Maybe I've missed some essential Python feature or syntax. But afaik, there's no good way to access dictionary by index right now. - That's exactly why I'm asking. Also Collections.OrderedDict doesn't provide by index access. Also keys, items or iter are all very slow methods of accessing specific index. With lists accessing by index is fast. With # project I'm now maintaining a list of keys for index access and dictionary for fast key access. But if ordered dictionary would allow direct index access, there wouldn't be a need to maintain separate list for index access. Any pro-tips would be appreciated. This is just the way I figured out to be the fastest so far for this use case. But I'm always looking for improvement. I'm just asking if there's a better way. I'm not proposing any syntax. Of course obvious would be new method to access / get by index. As bonus, it might al

      Sunday, 25-Dec-16 13:20:41 UTC from loadaverage.org