Good Python style?
- From: Andreas Beyer <mail@xxxxxxxxxx>
- Date: Thu, 31 May 2007 09:59:07 +0200
Hi,
I found the following quite cryptic code, which basically reads the
first column of some_file into a set.
In Python I am used to seeing much more verbose/explicit code. However,
the example below _may_ actually be faster than the usual "for line in ..."
Do you consider this code good Python style? Or would you recommend to
refrain from such complex single-line code??
Thanks!
Andreas
inp = resource(some_file)
# read first entries of all non-empty lines into a set
some_set = frozenset([line.split()[0] for line in \
filter(None, [ln.strip() for ln in inp])])
.
- Follow-Ups:
- Re: Good Python style?
- From: Alex Martelli
- Re: Good Python style?
- From: Virgil Dupras
- Re: Good Python style?
- From: Steven D'Aprano
- Re: Good Python style?
- Prev by Date: Re: c[:]()
- Next by Date: Researcher/Lecturer Position at MODUL University Vienna
- Previous by thread: Usage of the __and__ method
- Next by thread: Re: Good Python style?
- Index(es):
Relevant Pages
|