Good Python style?

rishi pathak mailmaverick666 at gmail.com
Thu May 31 04:42:04 EDT 2007


What if I want to process lines.In this case I would have to iterate over
the set and do the processing

On 5/31/07, Andreas Beyer <mail at a-beyer.de> wrote:
>
> 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])])
> --
> http://mail.python.org/mailman/listinfo/python-list
>



-- 
Regards--
Rishi Pathak
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20070531/653aff2a/attachment.html>


More information about the Python-list mailing list