what's faster: merging lists or dicts in python?

Posted by tipu on Stack Overflow See other posts from Stack Overflow or by tipu
Published on 2010-05-17T03:04:28Z Indexed on 2010/05/17 3:10 UTC
Read the original article Hit count: 304

Filed under:
|

I'm working with an app that is cpu-bound more than memory bound, and I'm trying to merge two things whether they be sets or dicts.

Now the thing is i can choose either one, but I'm wondering if merging dicts would be faster since it's all in memory? Or is it always going to be O(n), n being the size of the smaller set.

The reason I asked about dicts rather than sets is because I can't convert a set to json, because that results in {key1, key2, key3} and json needs a key/value pair, so I am using a dict so json dumps returns {key1:1, key2:1, key3:1}. Yes this is wasteful, but if it proves to be faster then I'm okay with it.

© Stack Overflow or respective owner

Related posts about python

Related posts about lists