Re: Lists and Tuples

Discussion in 'Python' started by Michael T. Babcock, Dec 5, 2003.

  1. 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
    Michael T. Babcock, Dec 5, 2003
    #1
    1. Advertising

  2. Michael T. Babcock

    Roy Smith Guest

    In article <>,
    "Michael T. Babcock" <> 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)
    Roy Smith, Dec 5, 2003
    #2
    1. Advertising


  3. >> 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
    Skip Montanaro, Dec 5, 2003
    #3
  4. 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>
    Fredrik Lundh, Dec 7, 2003
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Daniel Nogradi
    Replies:
    3
    Views:
    342
    Dennis Lee Bieber
    Nov 10, 2006
  2. Replies:
    5
    Views:
    540
    Thomas J. Gritzan
    Oct 6, 2006
  3. tuples within tuples

    , Oct 26, 2007, in forum: Python
    Replies:
    12
    Views:
    548
    Dennis Lee Bieber
    Oct 27, 2007
  4. xera121
    Replies:
    8
    Views:
    702
    lolmc
    Sep 30, 2009
  5. Jon Reyes
    Replies:
    18
    Views:
    217
    Mitya Sirenef
    Feb 19, 2013
Loading...

Share This Page