How can I avoid having to increment the sequence counter manually in the following Python code:
sequence = 0
for value in random.sample(range(1000), 7):
# do something with value and sequence
sequence += 1
Enumerate! You can refer to the Python docs.
for sequence, value in enumerate(random.sample(range(1000), 7)):
# do something with value and sequence
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