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
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
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
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
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()
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
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
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(
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
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 [('
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)
>
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')],
12 matches
Mail list logo