That you do not seem to be very similar to Pythonic. You should not remove material from the middle of the list, because lists are implemented as arrays in all Python implementations that I know of, so this is an O(n) operation.
If you really need this functionality as part of the algorithm, you should check out a data structure such as blist , which supports efficient removal from the middle.
In pure Python, what can you do if you do not need access to the rest of the elements, just shuffle the list first and then iterate over it:
lst = [1,2,3] random.shuffle(lst) for x in lst:
If you really need a remainder (which looks a bit like code, IMHO), at least you can pop() from the end of the list (which is fast!):
while lst: x = lst.pop()
In general, you can often express your programs more elegantly if you use a more functional style rather than changing the state (such as with a list).
Niklas B. Apr 6 '12 at 19:17 2012-04-06 19:17
source share