views:

108

answers:

1

Let's say I have a tuple (1,2,3,4). What's the simple way to change it into Array?

I can do something like this,

array = []
for i in tuple:
    array.append(i)

But I prefer something like x.toArray() or something.

+13  A: 

If you want to convert a tuple to a list (as you seem to want) use this:

>>> t = (1, 2, 3, 4)   # t is the tuple (1, 2, 3, 4)
>>> l = list(t)        # l is the list [1, 2, 3, 4]

In addition I would advise against using tupleas the name of a variable.

Mark Byers
+1. Correct answer and apt advice against using names of built in functions as variable names.
Manoj Govindan
+1 As simple as this answer seems, it is not always obvious to n00bs in the Python world.
Peter Rowell