Velocity Reviews > Re: Lists and Tuples

# Re: Lists and Tuples

Michael T. Babcock
Guest
Posts: n/a

 12-05-2003
I'm not sure if its a good answer or not, but I use tuples when the
number of items can't / won't change and arrays/lists when they may or
will change.

def get_values():
#... do stuff ...
return (x,y,z)

(x,y,z) = get_values()

PS, you can turn a tuple into a list quickly with list compressions;

list = [ x for x in tuple ]

--
Michael T. Babcock
C.T.O., FibreSpeed Ltd.
http://www.fibrespeed.net/~mbabcock

Roy Smith
Guest
Posts: n/a

 12-05-2003
In article <(E-Mail Removed)>,
"Michael T. Babcock" <(E-Mail Removed)> wrote:

> PS, you can turn a tuple into a list quickly with list compressions;
>
> list = [ x for x in tuple ]

What's wrong with the even simplier:

aList = list (aTuple)

Skip Montanaro
Guest
Posts: n/a

 12-05-2003

>> list = [ x for x in tuple ]

Roy> What's wrong with the even simplier:

Roy> aList = list (aTuple)

It doesn't use the language feature du jour.

Skip

Fredrik Lundh
Guest
Posts: n/a

 12-07-2003
Skip Montanaro wrote:

> >> list = [ x for x in tuple ]

>
> Roy> What's wrong with the even simplier:
>
> Roy> aList = list (aTuple)
>
> It doesn't use the language feature du jour.

list comprehensions have been around for ages. to show off,
you'll need to get itertools and generators into the mix.

</F>