-1

My data looks like:

X=[1,2,3,4]

But I need it to look like:

Y=[(1,2,3,4)]

How does one do this in python?

user3808752
  • 169
  • 4
  • 14
  • 1
    Do you have a good reason to do this? It may be more reasonable to make a list within a list such as `[[1,2,3,4]]` as tuples are immutable and may not behave like you would like. – Daniel Underwood Mar 07 '17 at 03:49
  • Possible duplicate of [Convert list to tuple in Python](http://stackoverflow.com/questions/12836128/convert-list-to-tuple-in-python) – Muhammad Haseeb Khan Mar 07 '17 at 03:55
  • Frankly I don't know. I'm querying data from a sql db that I want to chart using report lab. When I query the data I get a (?) list of tuples(?) that looks like [(1,),(2,),(3,),(4,)] which I've managed to get to [1,2,3,4]. Report labs renderPM function seems to be very finicky with how the chart data is presented... – user3808752 Mar 07 '17 at 04:07

2 Answers2

2

Try this:

l = [1,2,3,4]
l2 = [tuple(l)]
0

To do this is simple

>>> X = [1,2,3,4]
>>> [tuple(X)]
[(1, 2, 3, 4)]

Convert X to a tuple and wrap it in a list. This is only one of probably many ways to do this. It doesn't seem like a very useful thing, so if you could explain why you want to do this, we may be able to suggest some more useful code for you.

Paul Rooney
  • 20,879
  • 9
  • 40
  • 61
  • my original question is here [link](http://stackoverflow.com/questions/42603890/graphing-sqlite3-data-with-reportlab/42661640#42661640), in short I'm trying to chart data from a sql query using report lab. It was crashing at the function ( renderPM ) that creates the graphic file. After going through the report lab documentation I concluded it was how my data was presented. [(1,), (2,), (3,)] needed to be [(1,2,3)]......now struggling with making [(1,2,), (3,4,)] into [(1,3), (2,4)] – user3808752 Mar 08 '17 at 02:08