conditionals in lambdas?
Alex Martelli
aleaxit at yahoo.com
Fri Nov 3 17:13:45 EST 2000
More information about the Python-list mailing list
Fri Nov 3 17:13:45 EST 2000
- Previous message (by thread): conditionals in lambdas?
- Next message (by thread): conditionals in lambdas?
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
"Michael P. Soulier" <msoulier at nortelnetworks.com> wrote in message news:8tv6if$m79$1 at bmerhc5e.ca.nortel.com... [snip] > Thanks. I guess I'm still in that Perl mentality where I'm trying to do > many things on one line. Nothing intrinsically wrong with that. > I was looking for a simple way of grabbing all lines that began with a > the string #LOADDATA. In perl I'd do this: > > open (FILE, "file") or die "Can't open file: $!"; > @contents = grep { /^\#LOADDATA/ } <FILE>; SO verbose? Tch...! Python 2...: contents = [x for x in open("file").readlines() if x.startswith('#LOADDATA')] (you CAN cram it onto 1 line, but 1.5 read better:-). Alex
- Previous message (by thread): conditionals in lambdas?
- Next message (by thread): conditionals in lambdas?
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
More information about the Python-list mailing list