问题
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?
回答1:
Try this:
l = [1,2,3,4]
l2 = [tuple(l)]
回答2:
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.
来源:https://stackoverflow.com/questions/42639835/working-with-lists-and-tuples