I have a list of items (which are HTML table rows, extracted with Beautiful Soup) and I need to iterate over the list and get even and odd elements (I mean index) for each loop run.
My code looks like this:
for top, bottom in izip(table[::2], table[1::2]):
#do something with top
#do something else with bottom
How to make this code less ugly? Or maybe is it good way to do this?
EDIT:
table[1::2], table[::2] => table[::2], table[1::2]
Try:
This solution works on any sequence, not just lists, and doesn’t copy the sequence (it will be far more efficient if you only want the first few elements of a long sequence).