The default for loop only iterates through each item at a time. How can I make it so I can iterate through every 2 items?
You can use the slice notation:
for item in items[::2]:
print(item)
If you want to iterate pairwise every 2 items, you can do this:
for item1, item2 in zip(items[::2], items[1::2]):
print(item1, item2)
you can use:
for item in items[::2]:
<your_code>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With