Path: csiph.com!fu-berlin.de!uni-berlin.de!not-for-mail From: Chris Angelico Newsgroups: comp.lang.python Subject: Re: repeat items in a list Date: Tue, 29 Mar 2016 08:25:49 +1100 Lines: 35 Message-ID: References: <8935d5dc-5e62-4fa8-8e8f-bd5b1787ee9f@googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 X-Trace: news.uni-berlin.de T7z0/SUWQej+JwQBpjJUrwy4rxYRw+GdubEvFCJvFP3g== Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.025 X-Spam-Evidence: '*H*': 0.95; '*S*': 0.00; 'received:209.85.223': 0.03; 'failing': 0.05; 'nicely': 0.07; 'cc:addr:python-list': 0.09; '"if': 0.09; 'python': 0.10; 'language,': 0.11; '(but': 0.15; 'things.': 0.15; '2016': 0.16; 'erik': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'interest,': 0.16; 'lambda': 0.16; 'received:io': 0.16; 'received:psf.io': 0.16; 'task.': 0.16; 'wrote:': 0.16; 'tells': 0.18; '>>>': 0.20; 'cc:2**0': 0.20; 'cc:addr:python.org': 0.20; 'first,': 0.20; 'so.': 0.22; 'am,': 0.23; 'header:In-Reply-To:1': 0.24; 'subject:list': 0.26; 'figure': 0.27; 'message- id:@mail.gmail.com': 0.27; "skip:' 10": 0.28; 'went': 0.28; 'concise': 0.29; 'code': 0.30; 'language.': 0.32; 'tue,': 0.34; 'that,': 0.34; 'received:google.com': 0.35; 'problem.': 0.35; 'reply.': 0.35; 'sometimes': 0.35; 'but': 0.36; 'should': 0.36; 'instead': 0.36; 'there': 0.36; 'lines': 0.36; 'received:209.85': 0.36; 'subject:: ': 0.37; 'say': 0.37; 'thanks': 0.37; 'doing': 0.38; 'received:209': 0.38; 'minimum': 0.38; 'or,': 0.38; 'why': 0.39; 'easily': 0.39; 'where': 0.40; 'your': 0.60; "you'll": 0.61; 'show': 0.62; 'saturday,': 0.63; 'more': 0.63; 'march': 0.64; 'you.': 0.64; 'goal': 0.64; 'mar': 0.65; 'worth': 0.67; '26,': 0.72; 'capabilities': 0.72; '(generic': 0.84; 'chrisa': 0.84; 'expresses': 0.84; 'expressive': 0.84; 'goal:': 0.84; 'utc-4,': 0.84; 'to:none': 0.91; 'email addr:aol.com': 0.97 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:cc; bh=0pmT47k8UaoiZHRwJupXsSxikVtBbTi+pzRuec9dPyg=; b=WcMrUymIzgHansIgMnph8mb46bj1MM+vE70q5enqHUohPSXSC9TgyWN0rVykIqg2do etl0zlHdbua3CKNAJAkN8qpnp7vfFmEJAPuR4wh29yw4FsipvxFss7VR1+9KjRf+wJfP psNOjiBxs2jyvMNAjAx6mtQKwlrfUR99bE2VgXYYi4VSZ+dXx7nHagIzIjv5zEsB74Bt AV8uT3FjYlgOG3CmDFdAhwaYesLpNgodJznt/jxFAOV1E2KpADuFV2P1Pu5UA2aUMau7 /Tf49Y6H4gaprn3s+oavU21VvfZ2I+xK0jbWAlsJvQkgPY5bbEUYE38kVtAWC59vAhGo +fLQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:in-reply-to:references:date :message-id:subject:from:cc; bh=0pmT47k8UaoiZHRwJupXsSxikVtBbTi+pzRuec9dPyg=; b=OXqkXL9bKqJB8pP4geTTBDPJ8IuJonV55QTX9j6N+btAE1A4tHfI8MkPVBgQkzD4IF kS6J3PDbaOkaFqJySLwted+5cVxiOkcbU7/QT2BW6SyNGqlSmSWOn2KErJeWJFQqkI1d nx3zm4Ps0x5kOAqWv08hpPtnOcYGMUT2VJXy7H7G1GO4eLIZ3ZvmseexwAXmpqczFw0g zGUziVKVPGXlPOplBlTmyzxcP+o8gckAXFhPXKsQaYf52CMOGJfD1B9PrYpBxpCHq/Zm zlTuNxXNLyuyZTJReHrIwtHXiK8uong/NSvuHrgKMwnBLkOZcm3I1D4msy+sNKuw4srE XhRQ== X-Gm-Message-State: AD7BkJLqZ9pm7d4wV3VPDpLNiSVZLKtsDsdskojnf2izh9spCCSWvjlaGifBC8/f0jJXHEXrA7UFEwUPcP+a1g== X-Received: by 10.107.137.221 with SMTP id t90mr4946765ioi.31.1459200349794; Mon, 28 Mar 2016 14:25:49 -0700 (PDT) In-Reply-To: X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Xref: csiph.com comp.lang.python:105925 On Tue, Mar 29, 2016 at 4:30 AM, Rob Gaddi wrote: > beliavsky@aol.com wrote: > >> On Saturday, March 26, 2016 at 7:24:10 PM UTC-4, Erik wrote: >>> >>> Or, if you want to "import operator" first, you can use 'operator.add' >>> instead of the lambda (but you _did_ ask for a one-liner ;)). >>> >>> Out of interest, why the fascination with one-liners? >> >> Thanks for your reply. Sometimes when I program in Python I think I am not using the full capabilities of the language, so I want to know if there are >> more concise ways of doing things. > > Concise is only worth so much. PEP20 tells us "Explicit is better than > implicit", "Simple is better than complex" and "If the implementation is > hard to explain, it's a bad idea". > > Python is a beautifully expressive language. Your goal should not be to > write the minimum number of lines of code to accomplish the task. > Your goal should be to write the code such that your grandmother can > understand it. That way, when you screw it up, you'll be able to easily > figure out where and how you did so. Or failing that, you can get > grangran to show you. Just out of interest, did you (generic you) happen to notice Mark's suggestion? It's a one-liner that nicely expresses the intention and accomplishes the goal: yy = [aa for aa in xx for _ in range(nrep)] It quietly went through without fanfare, but I would say this is the perfect solution to the original problem. ChrisA