Re: finding a component in a list of pairs

2019-06-24 Thread Peter Pearson
[snip] > print( dict( pairs ).get( 'sun', '(unknown)' )) You probably know this, but . . . just in case . . . If you're doing this many times, you'll want to construct the dict just once and then make many references to the dict, rather than re-constructing the dict every time you want to look up

Re: finding a component in a list of pairs

2019-06-23 Thread Peter Pearson
On 22 Jun 2019 13:24:38 GMT, Stefan Ram 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