[Python-Dev] a feature i'd like to see in python #1: betteriteration control (original) (raw)
Raymond Hettinger python at rcn.com
Tue Dec 5 18:30:46 CET 2006
- Previous message: [Python-Dev] a feature i'd like to see in python #1: better iteration control
- Next message: [Python-Dev] a feature i'd like to see in python #1: betteriteration control
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
[Ben Wing ]
many times writing somewhat complex loops over lists i've found the need to sometimes delete an item from the list. currently there's no easy way to do so; basically, you have to write something like
[Adam Olsen]
As I don't believe there's any need for a language extension, I've posted my approach to this on comp.lang.python:
http://groups.google.com/group/comp.lang.python/browsethread/thread/724aa6bcf021cfad/c4c629bd1bacc12b#c4c629bd1bacc12b Note that deleting from the list as you iterate over it tends to have very poor performance for larger lists. My post includes some timings, demonstrating this.
Well said. And even if performance considerations could be addressed, it would be a crummy idea , leading people into knotty code. When looping over a structure, the act of actively inserting and deleting entries, can introduce unexpected feedback between loop control and the loop body. This is a recipe for bugs and hard-to-maintain code.
Overall, feature #1 is a non-starter and hopefully this thread will die quickly or move off-list.
Raymond
- Previous message: [Python-Dev] a feature i'd like to see in python #1: better iteration control
- Next message: [Python-Dev] a feature i'd like to see in python #1: betteriteration control
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]