simple question on dictionary usage

Ryan Ginstrom software at ginstrom.com
Sat Oct 27 01:53:15 EDT 2007


> On Behalf Of Edward Kozlowski
> I think this should do the trick.  There's probably something 
> more concise than this, but I can't think of it at the moment.
> 
> egt = {}
> for key in record:
>     if key.startswith('E'):
>         egt[key] = record[key]

Not much more concise, but another way:

egt = dict((key, record[key])
            for key in record
            if key.startswith('E'))

Regards,
Ryan Ginstrom




More information about the Python-list mailing list