simple question on dictionary usage

Frank Millman frank at chagford.com
Sat Oct 27 02:16:35 EDT 2007


On Oct 27, 8:02 am, Frank Millman <fr... at chagford.com> wrote:
> > This should work -
>
> > egt = dict([i for i in d.items() if i[0].startswith('E')])
>
> Of course I meant record.items(), not d.items(). Sorry.
>
> Frank

On reflection, although my solution is a bit shorter than some others,
it may not be as efficient, as it retrieves the key and value for
*every* entry in 'record' before testing whether the key begins with
'E'.

If the dictionary is large, this may be a consideration.

Frank




More information about the Python-list mailing list