accessing keys in dict

James Stroud jstroud at mbi.ucla.edu
Tue Aug 14 22:04:19 EDT 2007


james_027 wrote:
> hi,
> 
> a_dict = {'name':'apple', 'color':'red', 'texture':'smooth',
> 'shape':'sphere'}
> 
> is there any difference between ..
> 
> for key in a_dict:
> 
> from
> 
> for key in a_dict.keys():
> 
> 
> which is more preferred?

Use the first.

any difference in performance?

It doesn't matter. Wait until later to do these types of optimizations. 
Ask the list how to go about optimizing when the time comes.

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