Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #52139 > unrolled thread
| Started by | liuerfire Wang <liuerfire@gmail.com> |
|---|---|
| First post | 2013-08-07 16:56 +0800 |
| Last post | 2013-08-07 16:56 +0800 |
| Articles | 1 — 1 participant |
Back to article view | Back to comp.lang.python
This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by
below is the oldest one visible, not the original post.
Re: make elements of a list twice or more. liuerfire Wang <liuerfire@gmail.com> - 2013-08-07 16:56 +0800
| From | liuerfire Wang <liuerfire@gmail.com> |
|---|---|
| Date | 2013-08-07 16:56 +0800 |
| Subject | Re: make elements of a list twice or more. |
| Message-ID | <mailman.319.1375893821.1251.python-list@python.org> |
[Multipart message — attachments visible in raw view] — view raw
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 <liuerfire@gmail.com> 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]. > > I know we can do like that: > > tmp = [] > for i in x: > tmp.append(i) > tmp.append(i) > > However, I wander is there a more beautiful way to do it, like [i for i in > x]? > > Thanks. > > > -- > Best regards. > /********************************** > google+: +liuerfire <http://gplus.to/onepiece> twitter: @liuerfire<https://twitter.com/#!/liuerfire> > 蛋疼不蛋疼的都可以试着点一下~^_^~ <http://db.tt/YGEdRM0> > ***********************************/ > > -- Best regards. /********************************** google+: +liuerfire <http://gplus.to/onepiece> twitter: @liuerfire<https://twitter.com/#!/liuerfire> 蛋疼不蛋疼的都可以试着点一下~^_^~ <http://db.tt/YGEdRM0> ***********************************/
Back to top | Article view | comp.lang.python
csiph-web