allow line break at operators

Tim Chase python.list at tim.thechases.com
Mon Aug 15 13:40:10 CEST 2011


On 08/14/2011 11:28 PM, Seebs wrote:
> I tend to write stuff like
>
> 	foo.array_of_things.sort.map { block }.join(", ")
>
> I like this a lot more than
> 	array = foo.array_of_things
> 	sorted_array = array.sort()
> 	mapped_array = [block(x) for x in sorted_array]
> 	", ".join(mapped_array)

If you like the one-liner, this is readily written as

   ", ".join(block(x) for x in sorted(foo.array_of_things))

Modulo your gripes about string.join(), this is about as succinct 
(and more readable, IMHO) as your initial example.  I've got 
piles of these sorts of things in my ETL code.

-tkc







More information about the Python-list mailing list