[Tutor] Creating Sudoku

Luke Paireepinart rabidpoobear at gmail.com
Mon Apr 7 16:54:33 CEST 2008


W W wrote:
> Actually, a dictionary might be a good idea.
> I just played with this so youcan get a little picture.
> [snip]
>
> You could easily run int(val) to convert to the integer value to store
> in the dict. The other benefit is that python ignores whitespace in
> between dictionary elements, so you could do something to the effect
> of
>   
What are you talking about?  I don't understand what you mean by 
"ignores whitespace between dictionary elements."
> foo = {'1a': 1, '1b':2, '1c':3,
>            '2a': 0, '2b': 9, '2c': 6}
>
> Or something of similar nature.
>
> I suppose in favor of a 2d list, the loop would be a little more
> straighforward. With a dict, the pairs are in no particular order, so
> you would have to basically create the same loop for a 2d array, and
> then convert the values to strings.
>   
It's also easier if the 2d list is pre-initialized to "-"s, for example, 
then he can just print it out directly, and it'll format correctly.  
With the dictionary he has to jump through some hoops, and by his 
original post we can infer that he's probably not completely comfortable 
with Python yet, so it'll probably be harder for him to understand how 
to do this.

I can provide example code showing how simple it'd be, but then it'd 
give away the answer.


More information about the Tutor mailing list