Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #106061
| Path | csiph.com!fu-berlin.de!uni-berlin.de!not-for-mail |
|---|---|
| From | Michael Selik <michael.selik@gmail.com> |
| Newsgroups | comp.lang.python |
| Subject | Re: repeat items in a list |
| Date | Tue, 29 Mar 2016 22:05:16 +0000 |
| Lines | 27 |
| Message-ID | <mailman.198.1459342300.28225.python-list@python.org> (permalink) |
| References | <8935d5dc-5e62-4fa8-8e8f-bd5b1787ee9f@googlegroups.com> <nd8ag6$6gh$1@gioia.aioe.org> <29bb9c16-eef4-4c00-9e41-ce8419405c29@googlegroups.com> <ndb50q$b8e$2@gioia.aioe.org> <1459173882.380114.561434386.096F166A@webmail.messagingengine.com> <ndersg$394$1@ger.gmane.org> |
| Mime-Version | 1.0 |
| Content-Type | text/plain; charset=UTF-8 |
| X-Trace | news.uni-berlin.de W8owjvp63Dpfq3kY2a+AswmLlGg85XcyWKwlso8Ois4A== |
| Return-Path | <michael.selik@gmail.com> |
| X-Original-To | python-list@python.org |
| Delivered-To | python-list@mail.python.org |
| X-Spam-Status | OK 0.008 |
| X-Spam-Evidence | '*H*': 0.98; '*S*': 0.00; '[])': 0.09; 'lst': 0.09; '>>>': 0.15; "'a',": 0.16; "'b',": 0.16; "'c',": 0.16; '2016': 0.16; "['a',": 0.16; 'itertools': 0.16; 'received:io': 0.16; 'received:psf.io': 0.16; 'wrote:': 0.16; 'skip:l 30': 0.18; '>': 0.18; 'email addr:gmail.com>': 0.18; '>>>': 0.20; 'to:2**1': 0.21; 'import': 0.24; 'header:In-Reply-To:1': 0.24; 'subject:list': 0.26; 'message-id:@mail.gmail.com': 0.27; 'url:mailman': 0.30; 'url:python': 0.33; 'url:listinfo': 0.34; 'tue,': 0.34; 'received:google.com': 0.35; 'skip:i 20': 0.36; 'url:org': 0.36; 'received:209.85': 0.36; 'to:addr:python-list': 0.36; 'subject:: ': 0.37; 'turn': 0.37; 'received:209': 0.38; 'received:209.85.220': 0.38; 'url:mail': 0.40; 'to:addr:python.org': 0.40; 'mar': 0.65; 'sum': 0.69; 'trick.': 0.84 |
| DKIM-Signature | v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:references:in-reply-to:from:date:message-id:subject:to; bh=+X4C6rTOYnUf4Sqs+aHGMc3xPVmzZjBUYe52rE8+8hk=; b=t5BqO+bbc9pqV/06OYknWFmujBcE8V6yOhRA4bO8tvwbA5p/cq994vaQIJuWfRIWDJ ViE6cqQk9FFZT3/BO+lZLnVHl0heY7vfPmiDj8n/gWREn9DLUTeYocR4qc2Oh5fSA706 eR3DzIh6R7/cZArV4gZIFtlMpPSE/GUeHSCJ6A9dMutO4jk0nYTyacGaqL9zTQHEZ/a0 elQb3zqYWLkxsAKzf0C0UASwSkeKNoUd7z2Og1RTTFKOjmWHHRyZhZb4eK0V9ia0V38V xWE3JdusN3ATRjLzQWvhR3eQJ0vaaO08kC7y8namP5w7C7sd/XLdX4ET9nQ5t37d81xt 6tmA== |
| X-Google-DKIM-Signature | v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to; bh=+X4C6rTOYnUf4Sqs+aHGMc3xPVmzZjBUYe52rE8+8hk=; b=ZwW6kRSzNl+sT5FNbWFHrY7nTC2I9jV6rBDNoNixuThO5u+Q+6RRO7yjkhn4XWX76E TZWA5flJf4V9QMAfptzXgWwXcScwOtj22ZwHnAU1ft4eNsfX+oVGyl6zMnairL6oR3aS FidS2JzGgqqmoC34AtFRgVTKnIPgzgMzNzPZ5EvIg7LjOCEmyDfUaPL1AEZ4qVqIn0Mq ozSrOX5au7I+jGNVgbvwafLTQZLndneZyCG4vXD2ZKYZyVmdp4GFynX0egGBeqHyyQYt JyslnpNIdd2Z0VYA1Yp178E+pK9BUB7nZ/yNdFfOkZcxgVvdEFYwvByvCDkhoHSWUV63 iyog== |
| X-Gm-Message-State | AD7BkJJbixuj8GzPxraEWW0oZYy1ibcuybe8IYfyS7dPwa1ZIlbjeWQKBG2NiyPxJKnxv97hAVUVJusmAZmZ1Q== |
| X-Received | by 10.55.221.8 with SMTP id n8mr5830365qki.50.1459289126289; Tue, 29 Mar 2016 15:05:26 -0700 (PDT) |
| In-Reply-To | <ndersg$394$1@ger.gmane.org> |
| X-Mailman-Approved-At | Wed, 30 Mar 2016 08:51:40 -0400 |
| X-Content-Filtered-By | Mailman/MimeDel 2.1.21 |
| X-BeenThere | python-list@python.org |
| X-Mailman-Version | 2.1.21 |
| Precedence | list |
| List-Id | General discussion list for the Python programming language <python-list.python.org> |
| List-Unsubscribe | <https://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 | <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe> |
| Xref | csiph.com comp.lang.python:106061 |
Show key headers only | View raw
I prefer itertools.chain.from_iterable to the sum trick.
>>> from itertools import chain
>>> lst = list('abc')
>>> list(chain.from_iterable([s]*3 for s in lst))
['a', 'a', 'a', 'b', 'b', 'b', 'c', 'c', 'c']
On Tue, Mar 29, 2016 at 5:28 PM Vito De Tullio <vito.detullio@gmail.com>
wrote:
> Random832 wrote:
>
> > How do you turn ['a', 'c', 'b'] into ['a', 'a', 'a', 'c', 'c', 'c', 'b',
> > 'b', 'b']?
>
> >>> sum([[e]*3 for e in ['a', 'c', 'b']], [])
> ['a', 'a', 'a', 'c', 'c', 'c', 'b', 'b', 'b']
>
>
> --
> By ZeD
>
> --
> https://mail.python.org/mailman/listinfo/python-list
>
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
repeat items in a list beliavsky@aol.com - 2016-03-26 15:12 -0700
Re: repeat items in a list Cameron Simpson <cs@zip.com.au> - 2016-03-27 10:05 +1100
Re: repeat items in a list Erik <python@lucidity.plus.com> - 2016-03-26 23:23 +0000
Re: repeat items in a list beliavsky@aol.com - 2016-03-26 16:36 -0700
Re: repeat items in a list Rob Gaddi <rgaddi@highlandtechnology.invalid> - 2016-03-28 17:30 +0000
Re: repeat items in a list Chris Angelico <rosuav@gmail.com> - 2016-03-29 08:25 +1100
Re: repeat items in a list Antonio Caminero Garcia <tonycamgar@gmail.com> - 2016-03-29 01:43 -0700
Re: repeat items in a list Erik <python@lucidity.plus.com> - 2016-03-28 23:14 +0100
Re: repeat items in a list Mark Lawrence <breamoreboy@yahoo.co.uk> - 2016-03-26 23:28 +0000
Re: repeat items in a list beliavsky@aol.com - 2016-03-26 16:54 -0700
Re: repeat items in a list Paul Rubin <no.email@nospam.invalid> - 2016-03-26 22:35 -0700
Re: repeat items in a list Antonio Caminero Garcia <tonycamgar@gmail.com> - 2016-03-27 01:02 -0700
Re: repeat items in a list Antonio Caminero Garcia <tonycamgar@gmail.com> - 2016-03-27 01:30 -0700
Re: repeat items in a list Jussi Piitulainen <jussi.piitulainen@helsinki.fi> - 2016-03-27 14:09 +0300
Re: repeat items in a list larudwer <larudwer@freenet.de> - 2016-03-27 11:52 +0200
Re: repeat items in a list Antonio Caminero Garcia <tonycamgar@gmail.com> - 2016-03-27 04:13 -0700
Re: repeat items in a list larudwer <larudwer@freenet.de> - 2016-03-28 13:36 +0200
Re: repeat items in a list Random832 <random832@fastmail.com> - 2016-03-28 10:04 -0400
Re: repeat items in a list Vito De Tullio <vito.detullio@gmail.com> - 2016-03-29 23:25 +0200
Re: repeat items in a list Michael Selik <michael.selik@gmail.com> - 2016-03-29 22:05 +0000
Re: repeat items in a list Peter Otten <__peter__@web.de> - 2016-03-30 17:52 +0200
csiph-web