Nested dictionaries trouble

Bruno Desthuilliers bdesth.quelquechose at free.quelquepart.fr
Sat Apr 21 15:49:17 EDT 2007


IamIan a écrit :
> I am using the suggested approach to make a years list:
> 
> years = ["199%s" % x for x in range(0,10)]
> years += ["200%s" % x for x in range(0,10)]
> 
> I haven't had any luck doing this in one line though. Is it possible?

# Q, D and pretty obvious
years = ["199%s" % x for x in range(0,10)] + ["200%s" % x for x in 
range(0,10)]

# hardly more involved, and quite more generic
years = ["%s%s" % (c, y) for c in ("199", "201") for y in range(10)]



More information about the Python-list mailing list