Python Big O: the time complexities of different data structures in Python (www.pythonmorsels.com)
from ericjmorey@programming.dev to python@programming.dev on 18 May 2024 18:35
https://programming.dev/post/14265030

Trey Hunner writes:

This article is primarily meant to act as a Python time complexity cheat sheet for those who already understand what time complexity is and how the time complexity of an operation might affect your code. For a more thorough explanation of time complexity see Ned Batchelder’s article/talk on this subject.

Read Python Big O: the time complexities of different data structures in Python

#python

threaded - newest

RobotToaster@mander.xyz on 18 May 2024 20:03 next collapse

Damn, I was hoping someone had python running a Megadeus.

ericjmorey@programming.dev on 18 May 2024 20:21 collapse

I don’t know what that means

Midnitte@beehaw.org on 19 May 2024 11:57 collapse

<img alt="Big O notation or something I’m not a compsci" src="https://beehaw.org/pictrs/image/c01c1319-c381-4258-8710-4d24994b4532.webm">

cyrl@lemmy.world on 19 May 2024 10:43 next collapse

Cheers, always good to be aware of these concepts even if Pythons is far from ‘blazingly fast’

sugar_in_your_tea@sh.itjust.works on 20 May 2024 14:02 collapse

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.

Nomecks@lemmy.ca on 20 May 2024 14:55 collapse

Sets stay sorted, no?

sugar_in_your_tea@sh.itjust.works on 20 May 2024 15:01 collapse

Nope, sets are unordered.

Nomecks@lemmy.ca on 20 May 2024 15:07 collapse

Ah, sorry. Sets are unique, not ordered. Thanks!

sugar_in_your_tea@sh.itjust.works on 20 May 2024 16:40 collapse

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.