simple question on dictionary usage

Ryan Ginstrom software at
Sat Oct 27 07:53:15 CEST 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'))

Ryan Ginstrom

More information about the Python-list mailing list