[Python-ideas] str.split() oddness

Terry Reedy tjreedy at udel.edu
Mon Mar 7 03:13:30 CET 2011

On 3/6/2011 4:06 PM, Mart Sõmermaa wrote:

> Which do you prefer:
>    bar = dict(chunk.split('=') for chunk in foo.split(","))
> or
>    bar = (dict(chunk.split('=') for chunk in foo.split(",")) if foo else {})

Others have pointed out that one example is not representative of the 
universe of use cases of split. However, the irony of this example is 
the *you* are the one who prefers to add
   'if s != '' else []'
to the definition of s.split(c) ;-).

Terry Jan Reedy

More information about the Python-ideas mailing list