newbie - concatanating 2 lists

Steve Purcell stephen_purcell at yahoo.com
Wed Feb 21 12:41:27 EST 2001


Gnanasekaran Thoppae wrote:
> i am just beginning to use python.

Good choice!

> li1 = ['a', 'b', 'c']
> li2 = ['x', 'y', 'z']
> 
> i want:
> 
> li3 = ['ax', 'by', 'cz']

There may be more readable ways, but the shortest is probably this:

>>> li1 = ['a', 'b', 'c']
>>> li2 = ['x', 'y', 'z']
>>> li3 = map(lambda a,b: a+b, ['a','b','c'], ['x','y','z'])
>>> li3
['ax', 'by', 'cz']


-Steve

-- 
Steve Purcell, Pythangelist
Get testing at http://pyunit.sourceforge.net/
Get servlets at http://pyserv.sourceforge.net/
"Even snakes are afraid of snakes." -- Steven Wright




More information about the Python-list mailing list