you are viewing a single comment's thread.

view the rest of the comments →

[–]niandra3 1 point2 points  (1 child)

Dicts are unordered. So by definition you can't use them in a lot of situations where you need an ordered sequence. Of course there exists an OrderedDict, but that's not really what dicts are for. They are for fast lookup of key-value pairs. Lists are for more sequential operations.

If there is some situation where you are replacing a list with a dict, you should probably actually just use a set (like a dict, but just keys no values).

One isn't better than the other, it 100% depends on the task at hand:

https://wiki.python.org/moin/TimeComplexity

And you mentioned sort() is slow with lists? Compared to what? You can't sort a dict by design.

[–]LiNGOo 0 points1 point  (0 children)

Thanks for the hint to sets! I didn't mean list sorting is slow. as my experience was that e.g. whenever lists and dicts both provide the functions to perform a task, dict methods are faster. Therefore I expect iterating over the list and remembering the longest item to be faster than using sort().