51

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

top 9 comments
sorted by: hot top controversial new old
[-] cyrl@lemmy.world 4 points 5 months ago

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

[-] RobotToaster@mander.xyz 2 points 5 months ago

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

[-] ericjmorey@programming.dev 3 points 5 months ago

I don't know what that means

[-] sugar_in_your_tea@sh.itjust.works 2 points 5 months ago* (last edited 5 months ago)

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 1 points 5 months ago
[-] sugar_in_your_tea@sh.itjust.works 3 points 5 months ago* (last edited 5 months ago)
[-] Nomecks@lemmy.ca 1 points 5 months ago

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

[-] sugar_in_your_tea@sh.itjust.works 1 points 5 months ago

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.

this post was submitted on 18 May 2024
51 points (96.4% liked)

Python

6350 readers
2 users here now

Welcome to the Python community on the programming.dev Lemmy instance!

📅 Events

PastNovember 2023

October 2023

July 2023

August 2023

September 2023

🐍 Python project:
💓 Python Community:
✨ Python Ecosystem:
🌌 Fediverse
Communities
Projects
Feeds

founded 1 year ago
MODERATORS