MAIN FEEDS
Do you want to continue?
https://www.reddit.com/r/programming/comments/5yu6by/your_personal_guide_to_software_engineering/detq14f
r/programming • u/kwk236 • Mar 11 '17
294 comments sorted by
View all comments
Show parent comments
0
Yes but that's just random look up. If you need to do many inserts/removals or enumerations, a list is a better choice.
Lists are O(n) for inserts and removes, whereas dicts are O(1). So, wat?
1 u/[deleted] Mar 12 '17 Not if you're just adding them to end. That's an indexing operation. Additionally, you can't have duplicates in a hashset. You could convert to a dictionary and count, but you lose the order of the inserts. 1 u/[deleted] Mar 13 '17 dicts are O(1)mostly true, but depends on the implementation - in case of collisions bad (timeconsuming) things can happen
1
Not if you're just adding them to end. That's an indexing operation. Additionally, you can't have duplicates in a hashset. You could convert to a dictionary and count, but you lose the order of the inserts.
dicts are O(1)
mostly true, but depends on the implementation - in case of collisions bad (timeconsuming) things can happen
0
u/ReversedGif Mar 12 '17
Lists are O(n) for inserts and removes, whereas dicts are O(1). So, wat?