Is this a dream or a nightmare? (Was Re: XML)

Alex Martelli aleaxit at yahoo.com
Sun Oct 8 13:30:06 EDT 2000


> >         themap.setdefault(word,[]).append(fileinput.lineno())
    [snip]
> Wait a second. setdefault is new in 1.6/2.0, neither of which
> are the "real" python yet... So add two lines while themap.setdefault

1.6 is the latest released Python, so why wouldn't it be "real"?

> I couldn't find a way to do it in less than one full line in perl, but
> I'm not a perl hacker anymore, and even then, I don't think I ever
> wrote a oneliner.. even so:
>
> while(<>){for(split){$i{$_}.=++$L." "}}for(sort keys
%i){print"$_:$i{$_}\n"}

I may be missing something, but doesn't the ++ get repeated for each
incoming word?  If so, then this is building an index of word numbers,
not of line numbers.  Easy to fix, no doubt.


> anyway, that's half a line away from being 1/25th the size of the
> python version.. :)
>
> But so what? Who wants to write code like that?

Maybe a manager who pays by the line of code (and doesn't have to
worry about maintenance, because he'll be off to another job by the
time maintenance is needed) might prefer to purchase code written
in terms of (few) one-liners.  Why not?

However, by this way of counting, just about every Java program,
for example, can be made a 1-liner: just remove the line-ends and
change them into spaces (you may have to remove or recode the
comments ["what comments", one hears...:=)]).

Such simple juxtaposition of lines into "one line" can often be
done in Python just as well (and is just as irrelevant).  I often
omit the linebreak after the colon for a 1-liner-body if or try, for
example -- not the classic Python style, but a stylistic choice of
mine based on thinking that this tweak, when well used, can lead
to programs that are more easily read.  I don't do it in the illusion
that such "concision" changes anything substantial...


Alex




_________________________________________________________
Do You Yahoo!?
Get your free @yahoo.com address at http://mail.yahoo.com





More information about the Python-list mailing list