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>

 Thread Tools

 Posting Rules You may not post new threads You may not post replies You may not post attachments You may not edit your posts BB code is On Smilies are On [IMG] code is On HTML code is OffTrackbacks are On Pingbacks are On Refbacks are Off Forum Rules

 Similar Threads Thread Thread Starter Forum Replies Last Post Jon Reyes Python 18 02-19-2013 03:56 AM xera121 Python 8 09-30-2009 05:45 AM korovev76@gmail.com Python 12 10-27-2007 08:16 PM Daniel Nogradi Python 3 11-10-2006 07:57 AM fff_afafaf@yahoo.com C++ 5 10-05-2006 11:17 PM

Advertisments