I have a simple for loop:
for index, (key, value) in enumerate(self.addArgs["khzObj"].nodes.items()):
and I want to start a new wx horizontal boxsizer after every 3rd item to create a panel with 3 nodes each and going on for as many as are in nodes. The obvious solution is to do:
if index % 3 == 0: add a horizontal spacer
but the enumerate starts at 0, so 0 % 3 == 0 and it would start a new row right off the bat. I've tried doing:
if index == 0: index = index + 1
but of course that doesn't work because it creates a new var instead of changing the original -- so I get 1, 1, 2, 3, 4, etc and that won't work because I'll get 4 nodes before I hit a index % 3 == 0.
Any suggestions on how to do this? This isn't a big enumerate, usually only about 10-15 items. Thanks.
解决方案
Since Python 2.6, enumerate() takes an optional start parameter to indicate where to start the enumeration. See the documentation for enumerate.