Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #92539
| From | Mark Lawrence <breamoreboy@yahoo.co.uk> |
|---|---|
| Subject | Re: zip as iterator and bad/good practices |
| Date | 2015-06-12 17:22 +0100 |
| References | <mles66$sk2$1@speranza.aioe.org> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.430.1434126164.13271.python-list@python.org> (permalink) |
On 12/06/2015 16:00, Fabien wrote: > Folks, > > I am developing a program which I'd like to be python 2 and 3 > compatible. I am still relatively new to python and I use primarily py3 > for development. Every once in a while I use a py2 interpreter to see if > my tests pass through. > > I just spent several hours tracking down a bug which was related to the > fact that zip is an iterator in py3 but not in py2. Of course I did not > know about that difference. I've found the izip() function which should > do what I want, but that awful bug made me wonder: is it a bad practice > to interactively modify the list you are iterating over? > > I am computing mass fluxes along glacier branches ordered by > hydrological order, i.e. branch i is guaranteed to flow in a branch > later in that list. Branches are objects which have a pointer to the > object they are flowing into. > > In pseudo code: > > for stuff, branch in zip(stuffs, branches): > # compute flux > ... > # add to the downstream branch > id_branch = branches.index(branch.flows_to) > branches[id_branch].property.append(stuff_i_computed) > > So, all downstream branches in python2 where missing information from > their tributaries. It is quite a dangerous code but I can't find a more > elegant solution. > > Thanks! > > Fabien > Start here https://docs.python.org/3/howto/pyporting.html -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
zip as iterator and bad/good practices Fabien <fabien.maussion@gmail.com> - 2015-06-12 17:00 +0200
Re: zip as iterator and bad/good practices Fabien <fabien.maussion@gmail.com> - 2015-06-12 17:05 +0200
Re: zip as iterator and bad/good practices Ian Kelly <ian.g.kelly@gmail.com> - 2015-06-12 09:26 -0600
Re: zip as iterator and bad/good practices Fabien <fabien.maussion@gmail.com> - 2015-06-12 17:34 +0200
Re: zip as iterator and bad/good practices Fabien <fabien.maussion@gmail.com> - 2015-06-12 17:59 +0200
Re: zip as iterator and bad/good practices Mark Lawrence <breamoreboy@yahoo.co.uk> - 2015-06-12 17:22 +0100
Re: zip as iterator and bad/good practices Laura Creighton <lac@openend.se> - 2015-06-12 22:34 +0200
Re: zip as iterator and bad/good practices Terry Reedy <tjreedy@udel.edu> - 2015-06-12 19:27 -0400
Re: zip as iterator and bad/good practices Terry Reedy <tjreedy@udel.edu> - 2015-06-12 19:43 -0400
Re: zip as iterator and bad/good practices sohcahtoa82@gmail.com - 2015-06-12 17:02 -0700
Re: zip as iterator and bad/good practices Chris Angelico <rosuav@gmail.com> - 2015-06-13 10:26 +1000
Re: zip as iterator and bad/good practices sohcahtoa82@gmail.com - 2015-06-12 17:39 -0700
Re: zip as iterator and bad/good practices jimages <jimages123@gmail.com> - 2015-06-13 13:32 +0800
Re: zip as iterator and bad/good practices Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2015-06-13 07:17 +0000
Re: zip as iterator and bad/good practices Oscar Benjamin <oscar.j.benjamin@gmail.com> - 2015-06-13 13:48 +0100
Re: zip as iterator and bad/good practices Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2015-06-13 16:16 +0000
csiph-web