Path: csiph.com!news.swapon.de!eternal-september.org!feeder.eternal-september.org!mx02.eternal-september.org!.POSTED!not-for-mail From: Paul Rubin Newsgroups: comp.lang.python Subject: Re: repeat items in a list Date: Sat, 26 Mar 2016 22:35:28 -0700 Organization: A noiseless patient Spider Lines: 11 Message-ID: <8737rc7aan.fsf@nightsong.com> References: <8935d5dc-5e62-4fa8-8e8f-bd5b1787ee9f@googlegroups.com> <6f1ab11b-da4a-49d5-8dcd-bd9b0c6fe8b3@googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain Injection-Info: mx02.eternal-september.org; posting-host="ac130717aa033f117b1251f50cb4c61b"; logging-data="14620"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19erHBoJVEyAd6xyrgj6ITc" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3 (gnu/linux) Cancel-Lock: sha1:7is+yZZEyNZc0+clhhlvmLX3oUU= sha1:K3nwbft6Cno2HkPBKK6XlPjpKkY= Xref: csiph.com comp.lang.python:105816 beliavsky@aol.com writes: > yy = list(chain.from_iterable([list(repeat(aa,nrep)) for aa in xx])) The chain approach seems more natural to me: yy = list(chain.from_iterable(map(lambda x: [x,x], xx))) may make the doubling more obvious, and in Python 3 it should avoid the intermediate lists since map creates a generator. Depending on the usage, you might also not need the outermost list, making yy a lazy generator as well.