Strategy for determing difference between 2 very large dictionaries

James Stroud jstroud at mbi.ucla.edu
Wed Dec 24 03:57:35 EST 2008


Marc 'BlackJack' Rintsch wrote:
> On Wed, 24 Dec 2008 03:23:00 -0500, python wrote:
> 
>> Hi Gabriel,
>>
>> Thank you very much for your feedback!
>>
>>> k1 = set(dict1.iterkeys())
>> I noticed you suggested .iterkeys() vs. .keys(). Is there any advantage
>> to using an iterator vs. a list as the basis for creating a set? I
>> understand that an iterator makes sense if you're working with a large
>> set of items one at a time, but if you're creating a non-filtered
>> collection, I don't see the advantage of using an iterator or a list.
>> I'm sure I'm missing a subtle point here :)
> 
> `keys()` creates a list in memory, `iterkeys()` does not.  With
> ``set(dict.keys())`` there is a point in time where the dictionary, the 
> list, and the set co-exist in memory.  With ``set(dict.iterkeys())`` only 
> the set and the dictionary exist in memory.

For the purpose of perpetuating the annoying pedantry that has made 
usenet great:

 
http://docs.python.org/dev/3.0/whatsnew/3.0.html#views-and-iterators-instead-of-lists



James


-- 
James Stroud
UCLA-DOE Institute for Genomics and Proteomics
Box 951570
Los Angeles, CA 90095

http://www.jamesstroud.com



More information about the Python-list mailing list