osdir.com


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

Remove comma from tuples in python.


Gary Herron writes:

> On 02/20/2014 10:49 PM, Jaydeep Patil wrote:
> > I am getting below tuple from excel.
> > How should i remove extra commas in each tuple to make it easy for
> > operations.
> >
> > tuples is:
> > seriesxlist1 = ((0.0), (0.01), (0.02), (0.03), (0.04), (0.05), (0.06), (0.07), (0.08), (0.09), (0.1), (0.11))
> >
> > please suggest me solution.
> 
> There are no extra *commas* there.  Perhaps you mean extra

There were extra commas in a previous thread.

Jaydeep, Rustom Mody gave you the answer, which you even quoted but
apparently failed to notice. Go back and see.

That answer was this:

   >>> seriesxlist1 = ((0.0,), (0.01,), (0.02,))
   >>> x2 = [x*x for (x,) in seriesxlist1]

I tend to omit those parentheses and use just the comma:

   >>> x2 = [x*x for x, in seriesxlist1]