Re: make elements of a list twice or more.

2013-08-21 Thread Tobiah
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:

Re: make elements of a list twice or more.

2013-08-19 Thread alex23
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

Re: make elements of a list twice or more.

2013-08-07 Thread liuerfire Wang
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.

Re: make elements of a list twice or more.

2013-08-07 Thread Joshua Landau
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

Re: make elements of a list twice or more.

2013-08-07 Thread Peter Otten
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

Re: make elements of a list twice or more.

2013-08-07 Thread liuerfire Wang
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,