finding a component in a list of pairs

Peter Pearson pkpearson at nowhere.invalid
Sun Jun 23 13:58:02 EDT 2019


On 22 Jun 2019 13:24:38 GMT, Stefan Ram <ram at zedat.fu-berlin.de> wrote:
[snip]
>
> print( next( ( pair for pair in pairs if pair[ 0 ]== 'sun' ), 
>              ( 0, '(unbekannt)' ))[ 1 ])
> print( next( itertools.dropwhile( lambda pair: pair[ 0 ]!= 'sun', pairs ))
>              [ 1 ])
[snip]
>
>   The last two lines of the program show two different
>   approaches to search for the translation of »sun«.
>
>   Which approach is better? Or, do you have yet a better idea
>   about how to find the translation of »sun« in »pairs«?

Are you allowed to use a dict?

-- 
To email me, substitute nowhere->runbox, invalid->com.



More information about the Python-list mailing list