I have something like this:
for i, item in enumerate(weapons):
print "%s : %s" % (i, item)
print "#####"
for i, item in enumerate(weapons):
if item is not 'bananas':
print "%s : %s"%(i, item)
And I get this:
0: apples
1: bananas
2: oranges
3: pears
4: coconuts
#####
0: apples
2: oranges
3: pears
4: coconuts
But I would like to increase the 'i' only if it's used, creating
0: apples
1: oranges
2: pears
3: coconuts
What's the most pythonic way of doing this? I was using a predefined variable outside the for-loop and increasing it by 1 every iteration. Like this.
i = 0
for item in weapons:
if item is not 'bananas':
print "%s : %s"%(i, item)
i += 1
But it seems very ugly.