Re: pairwise combination of two lists

2011-08-18 Thread SigmundV
On Aug 17, 9:22 pm, Yingjie Lin wrote: > I found zip() but it only gives [('a', '1'), ('b', '2')],  not exactly what I > am looking for. Yet, if you feed the zip into a list comprehension you get what you want: li3 = [''.join(l) for l in zip(li1,li2)] Sigmund -- http://mail.python.org/mailma

Re: pairwise combination of two lists

2011-08-18 Thread Ian Kelly
On Wed, Aug 17, 2011 at 4:22 PM, Yingjie Lin wrote: > Hi Python users, > > I have two lists: > > li1 = ['a', 'b'] > li2 = ['1', '2'] > > and I wish to obtain a list like this > > li3 = ['a1', 'a2', 'b1', 'b2'] > > Is there a handy and efficient function to do this, especially when li1 and > li2 a

Re: pairwise combination of two lists

2011-08-18 Thread Alain Ketterlin
Yingjie Lin writes: > I have two lists: > > li1 = ['a', 'b'] > li2 = ['1', '2'] > > and I wish to obtain a list like this > > li3 = ['a1', 'a2', 'b1', 'b2'] > > Is there a handy and efficient function to do this, especially when > li1 and li2 are long lists. It's not difficult to write your own

Re: pairwise combination of two lists

2011-08-18 Thread Paul Rubin
Yingjie Lin writes: > li1 = ['a', 'b'] > li2 = ['1', '2'] > > and I wish to obtain a list like this > li3 = ['a1', 'a2', 'b1', 'b2'] from itertools import * li3 = list(chain.from_iterable(izip(li1,li2))) -- http://mail.python.org/mailman/listinfo/python-list

Re: pairwise combination of two lists

2011-08-17 Thread Gary Herron
On 08/17/2011 01:22 PM, Yingjie Lin wrote: Hi Python users, I have two lists: li1 = ['a', 'b'] li2 = ['1', '2'] and I wish to obtain a list like this li3 = ['a1', 'a2', 'b1', 'b2'] Is there a handy and efficient function to do this, especially when li1 and li2 are long lists. I found zip()

Re: pairwise combination of two lists

2011-08-17 Thread Luis M . González
This is the easiest and most pythonic way (IMHO): l3 = [i+e for i in li1 for e in li2] l3 ['a1', 'a2', 'b1', 'b2'] Regards, Luis -- http://mail.python.org/mailman/listinfo/python-list

Re: pairwise combination of two lists

2011-08-17 Thread Marc Christiansen
Yingjie Lin wrote: > Hi Python users, > > I have two lists: > > li1 = ['a', 'b'] > li2 = ['1', '2'] > > and I wish to obtain a list like this > > li3 = ['a1', 'a2', 'b1', 'b2'] > > Is there a handy and efficient function to do this, especially when > li1 and li2 are long lists. Depending on

Re: pairwise combination of two lists

2011-08-17 Thread Kev Dwyer
Yingjie Lin wrote: > Hi Python users, > > I have two lists: > > li1 = ['a', 'b'] > li2 = ['1', '2'] > > and I wish to obtain a list like this > > li3 = ['a1', 'a2', 'b1', 'b2'] > > Is there a handy and efficient function to do this, especially when li1 > and li2 are long lists. > I found zip(

Re: pairwise combination of two lists

2011-08-17 Thread Ned Deily
In article <98cc6556-11f3-4850-bd2b-30481b530...@mssm.edu>, Yingjie Lin wrote: > I have two lists: > > li1 = ['a', 'b'] > li2 = ['1', '2'] > > and I wish to obtain a list like this > > li3 = ['a1', 'a2', 'b1', 'b2'] > > Is there a handy and efficient function to do this, especially when li1

Re: pairwise combination of two lists

2011-08-17 Thread Mel
Yingjie Lin wrote: > I have two lists: > > li1 = ['a', 'b'] > li2 = ['1', '2'] > > and I wish to obtain a list like this > > li3 = ['a1', 'a2', 'b1', 'b2'] > > Is there a handy and efficient function to do this, especially when li1 > and li2 are long lists. > I found zip() but it only gives [('

Re: pairwise combination of two lists

2011-08-17 Thread Mel
Mel wrote: > Yingjie Lin wrote: >> I have two lists: >> >> li1 = ['a', 'b'] >> li2 = ['1', '2'] >> >> and I wish to obtain a list like this >> >> li3 = ['a1', 'a2', 'b1', 'b2'] [ ... ] > This seems to do it : > > mwilson@tecumseth:~$ python > Python 2.6.5 (r265:79063, Apr 16 2010, 13:09:56) >

pairwise combination of two lists

2011-08-17 Thread Yingjie Lin
Hi Python users, I have two lists: li1 = ['a', 'b'] li2 = ['1', '2'] and I wish to obtain a list like this li3 = ['a1', 'a2', 'b1', 'b2'] Is there a handy and efficient function to do this, especially when li1 and li2 are long lists. I found zip() but it only gives [('a', '1'), ('b', '2')],