[Tutor] Iterating over a long list with regular expressions andchanging each item?

Alan Gauld alan.gauld at btinternet.com
Mon May 4 19:50:30 CEST 2009


"Paul McGuire" <ptmcg at austin.rr.com> wrote

> For much of my own code, I find lists of string literals to be tedious to
> enter, and easy to drop a ' character.  This style is a little easier on 
> the
> eyes, and harder to screw up.
>
> 'case_def_gen':['case_def gen null'.split()],
> 'nsuff_fem_pl':['nsuff null null'.split()],

Shouldn't that be:

> 'case_def_gen':'case_def gen null'.split(),
> 'nsuff_fem_pl':'nsuff null null'.split(),

Otherwise you get a list inside a list.

> 'abbrev' :       T('abbrev null null'),
> 'adj' :              T('adj null null'),
> 'adv' :             T('adv null null'),}

> (Yes, I know PEP8 says *not* to add spaces to line up assignments or 
> other
> related values, but I think there are isolated cases where it does help 
> to
> see what's going on.  You could even write this as:

Absolutely! There are a few of the Python style PEPs that I disagree
with, this looks like another one.


-- 
Alan Gauld
Author of the Learn to Program web site
http://www.alan-g.me.uk/ 




More information about the Tutor mailing list