from random import randint
random_bits = 0
for i in range(32): # 32 bits
if randint(0, 1): # coin flip
random_bits |= 1 << i
print(f"Randomly generated: {bin(random_bits)}")Randomly generated: 0b111111001011000100101011000010
enumerate over rangerange is a built-in useful for loops iterating over integer sequences
Randomly generated: 0b111111001011000100101011000010
vanilla is delicious
chocolate is delicious
pecan is delicious
strawberry is delicious
range1: vanilla
2: chocolate
3: pecan
4: strawberry
lenenumerate built-in manages this for us
(counter, value)
0, then 1 etc.(0, 'vanilla')
(1, 'chocolate')
enumerate pair1: vanilla
2: chocolate
3: pecan
4: strawberry
enumerate also provides a start keyword, which sets the starting counter value
start=1 the counter values returned are 1 then 2 etc.enumerate let’s you loop over the contents of a sequence while still getting the index as you goenumerate instead of looping over a range and indexing
enumerate accepts a start keyword argument to specify the starting value of the count value (default 0)