Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #52139

Re: make elements of a list twice or more.

Path csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!xlned.com!feeder1.xlned.com!newsfeed.xs4all.nl!newsfeed1.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
Return-Path <liuerfire@gmail.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status UNSURE 0.254
X-Spam-Level **
X-Spam-Evidence '*H*': 0.57; '*S*': 0.08; 'wang': 0.07; 'tmp': 0.09; 'clear.': 0.16; 'subject:make': 0.16; 'elements': 0.16; 'wrote:': 0.18; 'wed,': 0.18; 'thanks.': 0.20; 'aug': 0.22; 'email addr:gmail.com&gt;': 0.22; 'header:In-Reply-To:1': 0.27; 'subject:list': 0.30; 'message-id:@mail.gmail.com': 0.30; 'twitter:': 0.31; 'received:google.com': 0.35; 'there': 0.35; "didn't": 0.36; 'list': 0.37; 'to:addr:python-list': 0.38; 'pm,': 0.38; 'to:addr:python.org': 0.39; 'new': 0.61; 'more': 0.64; 'different': 0.65; 'regards.': 0.65; 'here': 0.66; 'it!': 0.67; 'beautiful': 0.68; 'skip:r 40': 0.68; 'charset:gb2312': 0.80; 'skip:/ 30': 0.84; 'skip:\xb5 60': 0.84; 'url:tt': 0.84; '2013': 0.98
DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type; bh=mJym9Q754Q7bLydW4P/vMwsfJkudwkco0cKqTjrUU14=; b=HgCnMIpcrrYXdPO40Equ1w1MvnDov20jjwAKZpqsC3O7u7rZXrQIqETBa5wG/JY4Fg Giu9j1hDAkvlfvVAU5DTfpLU7ncBQ7fKKRnzt1+ZzpRsfrTp9UP7rsE8+MjdkZvQBZRW tMeEnHqc+jkfR1I9lpp61Yiex11QK5GIqgtx8Nocs6TBXWg7SRFvF/Lh/Iu03UFhBmks +hQHgHDuUBhuacARopR9noZAaxpJbKf8xfJKujDej7M4okF4ClaGJAyXMN3RaXumqrKk yuUmsAscuYQ1nTFUNUZI0VnUWGJgpnap/pafgDu9GlP7V/9LF7TmVo4JfTRNDjHOoqQL B/vg==
MIME-Version 1.0
X-Received by 10.220.198.133 with SMTP id eo5mr703158vcb.24.1375865763857; Wed, 07 Aug 2013 01:56:03 -0700 (PDT)
In-Reply-To <CAFysF+Sh=1_K9++GELiGjYe8t-T53m0_6H=5FZyL8XEer8t8XA@mail.gmail.com>
References <CAFysF+Sh=1_K9++GELiGjYe8t-T53m0_6H=5FZyL8XEer8t8XA@mail.gmail.com>
Date Wed, 7 Aug 2013 16:56:03 +0800
Subject Re: make elements of a list twice or more.
From liuerfire Wang <liuerfire@gmail.com>
To python-list@python.org
Content-Type multipart/alternative; boundary=001a11c1c4521d0ddf04e357b60f
X-Mailman-Approved-At Wed, 07 Aug 2013 18:43:40 +0200
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.15
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <http://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.319.1375893821.1251.python-list@python.org> (permalink)
Lines 95
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1375893821 news.xs4all.nl 15868 [2001:888:2000:d::a6]:46229
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:52139

Show key headers only | View raw


[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 comp.lang.python | Previous | Next | Find similar | Unroll thread


Thread

Re: make elements of a list twice or more. liuerfire Wang <liuerfire@gmail.com> - 2013-08-07 16:56 +0800

csiph-web