[Tutor] Naming variables
Peter Otten
__peter__ at web.de
Sun Jan 19 09:27:46 CET 2014
Pierre Dagenais wrote:
> I wish to fill a list called years[] with a hundred lists called
> year1900[], year1901[], year1902[], ..., year1999[]. That is too much
> typing of course. Any way of doing this in a loop? I've tried stuff like
> ("year" + str(1900)) = [0,0] but nothing works.
> Any solution?
Use a dict:
years = {}
for year in range(1900, 2000):
years[year] = [0, 0]
Then instead of
print year1982
you have to type
print years[1982]
More information about the Tutor
mailing list