Regular expression help
Marc 'BlackJack' Rintsch
bj_666 at gmx.net
Fri Jul 18 11:41:43 EDT 2008
On Fri, 18 Jul 2008 10:04:29 -0400, Russell Blau wrote:
> values = {}
> for expression in line.split(" "):
> if "=" in expression:
> name, val = expression.split("=")
> values[name] = val
> […]
>
> And when you get to be a really hard-core Pythonista, you could write
> the whole routine above in one line, but this seems clearer. ;-)
I know it's a matter of taste but I think the one liner is still clear
(enough)::
values = dict(s.split('=') for s in line.split() if '=' in s)
Ciao,
Marc 'BlackJack' Rintsch
More information about the Python-list
mailing list