Newbie getting confused again

It's me itsme at yahoo.com
Fri Mar 4 22:52:22 EST 2005


*bonk, bonk, bonk*

Now I feel better.

Thanks, everybody.   The "+" is indeed what I was looking for.    It just
didn't occur to me that this is the way you concatenate two lists together.
But of course, that makes sense, doesn't it?

Thanks again.


"Peter Hansen" <peter at engcorp.com> wrote in message
news:6e-dnSKKdPqah7TfRVn-oA at powergate.ca...
> It's me wrote:
> > If I have:
> >
> >     a = (1,2,3)
>
> Note that this is a tuple.
>
> > how do I ended up with:
> >
> >     res=[(1), (2), (3), (4), (5)]
>
> Not that this is a list.  The two aren't the same thing.
> If you don't understand the difference, you might want
> to review the tutorial or head over to the tutor list.
>
> Also note that (1) is just the same as 1, so what you
> show above is the same as res=[1, 2, 3, 4, 5].  Is that
> what you wanted?
>
> > without doing:
> >
> >     res=[(a[0]), (a[1]), (a[2]), (4), (5)]
>
> Presumably what you are asking is how you can create
> a new list (or tuple?) based on the contents of the
> original tuple "a" but with two more elements added?
>
> This will do precisely what you've described, though
> it does convert "a" from a tuple into a list because
> you couldn't concatenate (join together) the two objects
> otherwise:
>
>     res = list(a) + [4, 5]
>
>
> -Peter





More information about the Python-list mailing list