finding a component in a list of pairs

Peter Pearson pkpearson at nowhere.invalid
Mon Jun 24 12:36:15 EDT 2019


[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 an element.

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



More information about the Python-list mailing list