[Tutor] Lists on the fly?

Luke Paireepinart rabidpoobear at gmail.com
Sat Dec 23 00:50:46 CET 2006


Kent Johnson wrote:
> Carlos wrote:
>   
>> Hello,
>>
>> I am wondering if it is possible to create lists on the fly. The script 
>> that I'm working on needs a number of parameters, one of those is 
>> population, and this corresponds to the number of solutions that a 
>> genetic algorithm generates on each generation (iteration). The thing is 
>> that I need to generate one list for each population member and then 
>> append the corresponding population members to that particular list.
>>
>> This is only so you can have an idea:
>>
>> for i in range(5):
>>     'list_%i' % (i) = []
>>     
Note, though this is pretty arbitrary  :) and only saves you 2 characters...
You don't need to create a tuple if you're only packing in one value.
 >>> i = 1
 >>> 'list_%i' % i
'list_1'

works just fine.
HTH,
-Luke


More information about the Tutor mailing list