Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #52140
| Date | 2013-08-07 16:50 +0800 |
|---|---|
| Subject | make elements of a list twice or more. |
| From | liuerfire Wang <liuerfire@gmail.com> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.318.1375893821.1251.python-list@python.org> (permalink) |
[Multipart message — attachments visible in raw view] - view raw
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>
***********************************/
Back to comp.lang.python | Previous | Next — Next in thread | Find similar | Unroll thread
make elements of a list twice or more. liuerfire Wang <liuerfire@gmail.com> - 2013-08-07 16:50 +0800 Re: make elements of a list twice or more. alex23 <wuwei23@gmail.com> - 2013-08-20 13:42 +1000 Re: make elements of a list twice or more. Tobiah <toby@tobiah.org> - 2013-08-21 13:01 -0700
csiph-web