git.net

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

finding a component in a list of pairs


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.