I stumbled across the following code:
for i,a in enumerate(attributes):
labels.append(Label(root, text = a, justify = LEFT).grid(sticky = W))
e = Entry
The enumerate
function returns a generator object which, at each iteration, yields a tuple containing the index of the element (i
), numbered starting from 0
by default, coupled with the element itself (a
), and the for
loop conveniently allows you to access both fields of those generated tuples and assign variable names to them.