another dictionary q

Alex Martelli aleaxit at yahoo.com
Sun Nov 2 10:56:28 CET 2003


ruari mactaggart wrote:

> can this be tidied up ?
> 
>>>>verb={}
>>>>verb[infinitive]=[['','','','','',''],['','','','','',''],['','','','',''
> ,''],['','','','','',''],['','','','','',''],['','','','','','']]
> 
> it is to create a dictionary entry with six empty lists of six items as
> values.

verb[infinitive] = [ [""]*6 for i in range(6) ]

is more concise and saves you from counting errors.


> or is it unnecesary ? They represent six tenses with six persons in each
> for an italian verb translator.

Whether it's necessary or not depends on how your application uses those
data, so I'm not sure how I can answer the question (despite being 
Italian:-).


Alex





More information about the Python-list mailing list