Re: Newbie getting confused again

2005-03-05 Thread It's me
Thanks, got it.


"M.E.Farmer" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
> It's me wrote:
> > If I have:
> >
> > a = (1,2,3)
> >
> > how do I ended up with:
> >
> > res=[(1), (2), (3), (4), (5)]
> >
> > without doing:
> >
> > res=[(a[0]), (a[1]), (a[2]), (4), (5)]
> >
> > ???
> >
> > ps: This is just a nobrainer example of what my real code is trying
> to do.
> > "a" might have many many elements.   That's why the explicit indexing
> method
> > won't work.
> >
> > Thanks,
> Hello,
> List objects have a method called extend().
> It is made for this.
> Py> a = [1,2,3]
> Py> b = [4,5,6]
> Py> a.extend(b)
> Py> a
> [1, 2, 3, 4, 5, 6]
> Since you are a newbie I also suggest you look at
> your objects a little and see what they have available.
>
> Py>dir(a)
> ['__add__', '__class__', '__contains__', '__delattr__', '__delitem__',
> '__delslice__', '__doc__', '__eq__', '__ge__', '__getattribute__',
> '__getitem__', '__getslice__', '__gt__', '__hash__', '__iadd__',
> '__imul__', '__init__', '__le__', '__len__', '__lt__', '__mul__',
> '__ne__', '__new__', '__reduce__', '__repr__', '__rmul__',
> '__setattr__', '__setitem__', '__setslice__', '__str__', 'append',
> 'count', 'extend', 'index', 'insert', 'pop', 'remove', 'reverse',
> 'sort']
>
> Then you can try and get some help from Python.
> Py>help(a.extend)
> Help on built-in function extend:
>
> extend(...)
> L.extend(iterable) -- extend list by appending elements from the
> iterable
>
> And finally use pydoc it is very helpful.
> Cl> python pydoc -g
> hth,
> M.E.Farmer
>


-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Newbie getting confused again

2005-03-05 Thread M.E.Farmer
It's me wrote:
> If I have:
>
> a = (1,2,3)
>
> how do I ended up with:
>
> res=[(1), (2), (3), (4), (5)]
>
> without doing:
>
> res=[(a[0]), (a[1]), (a[2]), (4), (5)]
>
> ???
>
> ps: This is just a nobrainer example of what my real code is trying
to do.
> "a" might have many many elements.   That's why the explicit indexing
method
> won't work.
>
> Thanks,
Hello,
List objects have a method called extend().
It is made for this.
Py> a = [1,2,3]
Py> b = [4,5,6]
Py> a.extend(b)
Py> a
[1, 2, 3, 4, 5, 6]
Since you are a newbie I also suggest you look at
your objects a little and see what they have available.

Py>dir(a)
['__add__', '__class__', '__contains__', '__delattr__', '__delitem__',
'__delslice__', '__doc__', '__eq__', '__ge__', '__getattribute__',
'__getitem__', '__getslice__', '__gt__', '__hash__', '__iadd__',
'__imul__', '__init__', '__le__', '__len__', '__lt__', '__mul__',
'__ne__', '__new__', '__reduce__', '__repr__', '__rmul__',
'__setattr__', '__setitem__', '__setslice__', '__str__', 'append',
'count', 'extend', 'index', 'insert', 'pop', 'remove', 'reverse',
'sort']

Then you can try and get some help from Python.
Py>help(a.extend)
Help on built-in function extend:

extend(...)
L.extend(iterable) -- extend list by appending elements from the
iterable

And finally use pydoc it is very helpful.
Cl> python pydoc -g
hth,
M.E.Farmer

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Newbie getting confused again

2005-03-04 Thread It's me
*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" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
> 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


-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Newbie getting confused again

2005-03-04 Thread Peter Hansen
Peter Hansen wrote:
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.
  
I meant to say "Note" here, not "Not"... in case it wasn't
obvious.
-Peter
--
http://mail.python.org/mailman/listinfo/python-list


Re: Newbie getting confused again

2005-03-04 Thread Peter Hansen
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
--
http://mail.python.org/mailman/listinfo/python-list


Re: Newbie getting confused again

2005-03-04 Thread John Machin

It's me wrote:
> If I have:
>
> a = (1,2,3)
>
> how do I ended up with:
>
> res=[(1), (2), (3), (4), (5)]
>
> without doing:
>
> res=[(a[0]), (a[1]), (a[2]), (4), (5)]
>

If by (x) you really mean a tuple with 1 element i.e. (x,) then you
need something like this:

>>> a = (1, 2, 3)
>>> b = [(4,), (5,)]
>>> res = [tuple([x]) for x in a] + b
>>> res
[(1,), (2,), (3,), (4,), (5,)]
>>>

Otherwise (a simpler requirement):

>>> a = (1, 2, 3)
>>> b = [4, 5]
>>> res = list(a) + b
>>> res
[1, 2, 3, 4, 5]
>>>

If NEITHER of the above is what you want, you'll need to try being a
bit clearer about what you are trying to achieve.

And a tip: if "a" is really of variable length, you should make it a
list, not a tuple; read the FAQ.

HTH,
John

-- 
http://mail.python.org/mailman/listinfo/python-list


Newbie getting confused again

2005-03-04 Thread It's me
If I have:

a = (1,2,3)

how do I ended up with:

res=[(1), (2), (3), (4), (5)]

without doing:

res=[(a[0]), (a[1]), (a[2]), (4), (5)]

???

ps: This is just a nobrainer example of what my real code is trying to do.
"a" might have many many elements.   That's why the explicit indexing method
won't work.

Thanks,





-- 
http://mail.python.org/mailman/listinfo/python-list