Howto find dict members from a list of keys

Steven D'Aprano steve at REMOVEME.cybersource.com.au
Thu Mar 8 03:37:48 EST 2007


On Thu, 08 Mar 2007 05:26:22 -0300, Gabriel Genellina wrote:

> En Thu, 08 Mar 2007 05:20:20 -0300, Alexander Eisenhuth  
> <newsuser at stacom-software.de> escribió:
> 
>> what algo do you use, when you want to find the dict values from d, with  
>> members
>> of l. Following example:
>>
>>  >>> d = {1:2,2:3,3:4,4:5,5:6,6:7,7:8,8:9,9:10}
>>  >>> l = [7,8]
>>  >>> found_dic_members = <yourCode>
>>  >>> print found_dict_members
>> [8,9]
> 
> found_dic_members = [d[key] for key in l]

*self stares at the line of code*

*self thinks about what he just posted*

*self realises with acute embarrassment that he's jumped to conclusions
and completely misunderstood the Original Poster's question*

Oops! I'll just be slinking away now... 



-- 
Steven D'Aprano 




More information about the Python-list mailing list