simple question on dictionary usage

George Sakkis george.sakkis at gmail.com
Mon Oct 29 02:57:37 CET 2007


On Oct 27, 8:58 am, Marc 'BlackJack' Rintsch <bj_... at gmx.net> wrote:
> On Sat, 27 Oct 2007 05:23:30 -0700, bearophileHUGS wrote:
> > My take too :-)
>
> > dict(item for item in record.iteritems() if item[0][0] == 'E')
>
> ``s.startswith('E')`` is a little safer than ``s[0] == 'E'`` as the former
> returns `False` if `s` is empty while the latter raises an `IndexError`.

A string slice is safe and faster though: if s[:1] == 'E'.

George




More information about the Python-list mailing list