[Tutor] Having trouble with a dictionary of lists

William Witteman yam at nerd.cx
Fri Sep 4 20:17:16 CEST 2009


On Fri, Sep 04, 2009 at 09:54:20AM -0700, Emile van Sebille wrote:
>On 9/4/2009 9:09 AM William Witteman said...
>>On Thu, Sep 03, 2009 at 11:26:35AM -0700, Emile van Sebille wrote:
>>
>>Thanks to Emile for pointing out the error.  There were several other
>>errors - initiating the counter in the loop (d'oh!), premature sorting
>>of the dictionary by keys, not providing an index row for the output
>>file, not returning anything from my function, and probably others.
>>
>>Here is how it looks now - any pointers, stylistic or otherwise, are
>>welcome.  It does, however, work.
>
>That's normally when I stop looking at it.  If I'm lucky, I'll never
>need to work on it again.  If and when I do, that's when I clean it
>up in the area that needs attention.  It's way to easy IMHO to turn
>one-off projects into time-sinks.
>
>Anyway, some notes interspersed below...

Thanks!

>>  toprow = [x for x in range(len(sslists))]
>
>This looks like toprow is simply range(len(sslists))...

Yes, until this next row...

>>  toprow.insert(0, "index")


>>      termdict[term] = ["" for x in range(number_of_columns)]
>
>this might also be said  [""]*number_of_columns

I was concerned that this would give me this:

[""],[""],[""]

rather than this:

["","",""]

I see now that it doesn't but the list comprehension seems really fast
compared to the multiplication.  Is that true?
-- 

yours,

William



More information about the Tutor mailing list