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: 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>': 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: References: Date: Wed, 7 Aug 2013 16:56:03 +0800 Subject: Re: make elements of a list twice or more. From: liuerfire Wang 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 List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: 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 --001a11c1c4521d0ddf04e357b60f Content-Type: text/plain; charset=GB2312 Content-Transfer-Encoding: quoted-printable 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 =3D [b, a, c] (a, b, c are elements of x. Each of them a= re > different type). Now I wanna generate a new list as [b, b, a, a, c, c]. > > I know we can do like that: > > tmp =3D [] > 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 i= n > x]? > > Thanks. > > > -- > Best regards. > /********************************** > google+: +liuerfire twitter: @liuerfire > =B5=B0=CC=DB=B2=BB=B5=B0=CC=DB=B5=C4=B6=BC=BF=C9=D2=D4=CA=D4=D7=C5=B5=E3= =D2=BB=CF=C2~^_^~ > ***********************************/ > > --=20 Best regards. /********************************** google+: +liuerfire twitter: @liuerfire =B5=B0=CC=DB=B2=BB=B5=B0=CC=DB=B5=C4=B6=BC=BF=C9=D2=D4=CA=D4=D7=C5=B5=E3=D2= =BB=CF=C2~^_^~ ***********************************/ --001a11c1c4521d0ddf04e357b60f Content-Type: text/html; charset=GB2312 Content-Transfer-Encoding: quoted-printable
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 d= idn't make clear.

Here is a list x =3D [b, a, c] (a,= b, c are elements of x. Each of them are different type).  Now I wann= a generate a new list as [b, b, a, a, c, c].

I know we can do like that:
tmp =3D []
for i i= n x:
    tmp.append(i)
    tmp.appe= nd(i)

However, I wander is there a more beautiful way to = do it, like [i for i in x]?

Thanks.


--=
Best regards.
/**********************************



--
Best re= gards.
/**********************************
--001a11c1c4521d0ddf04e357b60f--