sorted_sequence.index(item)
Shouldn't this be O(n log n)
? I guess Python doesn't have a list that stays sorted.
As a workaround, just use dict keys with no values instead.
Welcome to the Python community on the programming.dev Lemmy instance!
Past
November 2023
October 2023
July 2023
August 2023
September 2023
sorted_sequence.index(item)
Shouldn't this be O(n log n)
? I guess Python doesn't have a list that stays sorted.
As a workaround, just use dict keys with no values instead.
Sets stay sorted, no?
Nope, sets are unordered.
Ah, sorry. Sets are unique, not ordered. Thanks!
Yeah, I just think it's kind of odd though. If a language only has lists and hash maps, my go-to is to use a hash map for uniqueness, and sort the list for ordered lists.
But in Python, it's backwards where I use the hash map (dict) for ordered data and the set for uniqueness, because hash maps are unordered in most languages I've used.
Cheers, always good to be aware of these concepts even if Pythons is far from 'blazingly fast'
Damn, I was hoping someone had python running a Megadeus.
I don't know what that means