I was trying to create a list of lambda functions for a list of strings.
columns = ['a', 'b', 'c']
formats = []
for i, v in enumerate(columns)
formats.append(lambda x: str(i + 1) + '%4f' %x)
and the output of formats[0](12)
was supposed to be 1:12.0000
but the result turns out that no mater I use formats[0](13)
, formats[1](26)
or formats[2](12)
, the output is always like 3:##.####
.
It seems that it always keep the format of the last loop. Why? Could anyone help?