Parsing of a file

bearophileHUGS at lycos.com bearophileHUGS at lycos.com
Wed Aug 6 22:04:21 EDT 2008


Paul McGuire:
> This code creates a single dict for the input lines, keyed by id.
> Each value contains elements labeled 'id', 'ra', and 'mjd'.
...
> d = dict(
>             (rec.split()[1][:-1],
>              dict([('id',rec.split()[1][:-1])] +
>                   [map(str.lower,f.split('='))
>                       for f in rec.split()[2:5]] ) )
>              for rec in data
>         )
...

Please, don't try to shove the program in one line, use PyParsing :o)

Bye,
bearophile



More information about the Python-list mailing list