Q:

Create a New List from a List of Lists and print exactly in Python

I want to create a List from a List of Lists in Python. This is my approach
    grid=[[0,1,1], \
          [1,0,1], \
          [1,1,1], \
          [1,0,0]]
    grid2=[]
    for x in range(0,len(grid)):
     for y in range(0,len(grid[x])):
       if grid[x][y]==0:
         grid2.append(22)
       if grid[x][y]==1:
         grid2.append(44)

    for item in grid2:print grid2

The output that I expected is in grid2 the list will be like this:
22,44,44
44,22,44
44,44,44
44,22,22

But it seems my logic is wrong. Need some help

A:

You need to treat grid2 as a list of lists.  At least that's what I think you are trying to do.  
grid=[[0,1,1], \
      [1,0,1], \
      [1,1,1], \
      [1,0,0]]
grid2=[]
for x in range(0,len(grid)):
    grid2.append([])
    for y in range(0,len(grid[x])):
        if grid[x][y]==0:
           grid2[x].append(22)
        if grid[x][y]==1:
           grid2[x].append(44)

for item in grid2:
    print ','.join([str(x) for x in item])

