Path: csiph.com!fu-berlin.de!uni-berlin.de!not-for-mail From: Mark Lawrence Newsgroups: comp.lang.python Subject: Re: Simple exercise Date: Mon, 14 Mar 2016 15:23:26 +0000 Lines: 37 Message-ID: References: <88c5b5fa-66a0-461a-8ae4-b3264b32f679@googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain; charset=windows-1252; format=flowed Content-Transfer-Encoding: 7bit X-Trace: news.uni-berlin.de E/aQHLTZDFcZM21Mmui2xgq7XxEOS53tblrdbCaInQ0A== Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.007 X-Spam-Evidence: '*H*': 0.99; '*S*': 0.00; 'from:addr:yahoo.co.uk': 0.05; 'reason,': 0.07; '[1,': 0.09; 'benjamin': 0.09; 'length.': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'warn': 0.09; 'index': 0.13; '2016': 0.16; 'dropping': 0.16; 'iterables': 0.16; 'len': 0.16; 'length,': 0.16; 'received:80.91.229.3': 0.16; 'received:io': 0.16; 'received:plane.gmane.org': 0.16; 'received:psf.io': 0.16; 'wrote:': 0.16; 'language': 0.19; 'meant': 0.22; 'lawrence': 0.22; 'pass': 0.22; 'header:In-Reply- To:1': 0.24; 'header:User-Agent:1': 0.26; 'header:X-Complaints- To:1': 0.26; 'error': 0.27; 'function': 0.28; 'values': 0.28; 'strongly': 0.30; 'anyone': 0.32; 'language.': 0.32; 'url:python': 0.33; 'items.': 0.33; 'subject:Simple': 0.33; 'url:org': 0.36; 'url:library': 0.36; 'to:addr:python-list': 0.36; 'subject:: ': 0.37; 'two': 0.37; 'received:org': 0.37; 'johnson': 0.37; 'no,': 0.38; 'or,': 0.38; 'rather': 0.39; 'to:addr:python.org': 0.40; 'mark': 0.40; 'url:3': 0.60; 'avoid': 0.61; 'charset:windows-1252': 0.62; 'course': 0.62; 'necessarily': 0.63; 'our': 0.64; 'march': 0.64; 'matter.': 0.66; 'percent': 0.66; 'oscar': 0.84; 'pythonistas,': 0.84; 'absolutely': 0.88; 'safer': 0.91; 'rick': 0.93; 'hundred': 0.96 X-Injected-Via-Gmane: http://gmane.org/ X-Gmane-NNTP-Posting-Host: 80.234.129.0 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:38.0) Gecko/20100101 Thunderbird/38.6.0 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:104824 On 14/03/2016 15:06, Oscar Benjamin wrote: > On 14 March 2016 at 14:35, Rick Johnson wrote: >> >> I would strongly warn anyone against using the zip function >> unless > ... >> I meant to say: absolutely, one hundred percent *SURE*, that >> both sequences are of the same length, or, absolutely one >> hundred percent *SURE*, that dropping values is not going to >> matter. For that reason, i avoid the zip function like the >> plague. I would much rather get an index error, than let an >> error pass silently. > > I also think it's unfortunate that zip silently discards items. Almost > always when I use zip I would prefer to see an error when the two > iterables are not of the same length. Of course you're not necessarily > safer with len and range: > > a = [1, 2, 3] > b = 'abcde' > > for n in range(len(a)): > print(a[n], b[n]) > > -- > Oscar > This is a job for Bi, no, https://docs.python.org/3/library/itertools.html#itertools.zip_longest -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence