[Tutor] taking input for a list in a list

Peter Otten __peter__ at web.de
Mon Sep 26 15:42:22 CEST 2011

surya k wrote:

> Actually my programming language is C.. learning python.
> I'm trying to write sudoku program for which I need to take input.
> This is what I did merely
> *list = []
> for i in range (0,4) :
>       for j in range (0,4) :
>            list[i][j].append (" int (raw_input("Enter") ) )
> *
> This is completely wrong.. but I couldn't handle this kind of.. how do I..
> Actually I need a list in a list to handle sudoku.
> for a simple list to get input.. this would obviously work..
> *list.append ( int(raw_input("Enter") )*
> Can you tell me how do I do this correctly ?

Break the problem down to one you already know how to solve: if you add a 
new inner list for the columns to the outer list of rows adding an entry to 
the row means just appending an integer to the inner list:

def input_int():
    return int(raw_input("Enter an integer "))

square = []
N = 4
for i in range(N):
    row = []
    for k in range(N):

More information about the Tutor mailing list