Newbie getting confused again
mefjr75 at hotmail.com
Sat Mar 5 17:21:48 CET 2005
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), (a), (a), (4), (5)]
> ps: This is just a nobrainer example of what my real code is trying
> "a" might have many many elements. That's why the explicit indexing
> won't work.
List objects have a method called extend().
It is made for this.
Py> a = [1,2,3]
Py> b = [4,5,6]
[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.
['__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',
Then you can try and get some help from Python.
Help on built-in function extend:
L.extend(iterable) -- extend list by appending elements from the
And finally use pydoc it is very helpful.
Cl> python pydoc -g
More information about the Python-list