On 08/07/2013 01:50 AM, liuerfire Wang wrote:
> Sorry for the title which didn't make clear.
>
> Here is a list x = [b, a, c] (a, b, c are elements of x. Each of them are
> different type). Now I wanna generate a new list as [b,
> b, a, a, c, c].
If you don't care about the order, you can do:
On 7/08/2013 6:50 PM, liuerfire Wang wrote:
> Here is a list x = [b, a, c] (a, b, c are elements of x. Each of them
> are different type). Now I wanna generate a new list as [b, b, a, a, c, c].
from itertools import chain
new_list = list(chain.from_iterable(zip(x,x)))
--
http://mail.python.org
On Thu, Aug 8, 2013 at 6:18 AM, Joshua Landau wrote:
>
> I'm actually posting to point out
> http://www.python.org/dev/peps/pep-0448/ would let you write:
>
> [*(item, item) for item in items]
It seems like that it can be only used in python 3.4? I just use python 2.7
because of work needs.
On 7 August 2013 17:59, Peter Otten <__pete...@web.de> wrote:
> liuerfire Wang wrote:
>
>> Here is a list x = [b, a, c] (a, b, c are elements of x. Each of them are
>> different type). Now I wanna generate a new list as [b, b, a, a, c, c].
>>
>> I know we can do like that:
>>
>> tmp = []
>> for i
liuerfire Wang wrote:
> Here is a list x = [b, a, c] (a, b, c are elements of x. Each of them are
> different type). Now I wanna generate a new list as [b, b, a, a, c, c].
>
> I know we can do like that:
>
> tmp = []
> for i in x:
> tmp.append(i)
> tmp.append(i)
>
> However, I wander i
I got it!
It can do like [i for i in x for y in range(2)]
On Wed, Aug 7, 2013 at 4:50 PM, liuerfire Wang wrote:
> Sorry for the title which didn't make clear.
>
> Here is a list x = [b, a, c] (a, b, c are elements of x. Each of them are
> different type). Now I wanna generate a new list as [b,