osdir.com


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Remove comma from tuples in python.


Tim Chase wrote:

> With the single-value tuple, I tend to find the parens make it more
> readable, so I'd go with
> 
> [x*x for (x,) in lst]
 
Hardly ever seen in the wild, but unpacking works with [...], too:

>>> items = zip(range(5))
>>> [x*x for [x] in items]
[0, 1, 4, 9, 16]