but it goes into newline with each number
That’s because you add the newline after each number instead of after each sublist r. If you want that instead, you should append the newline there:
c = ''
for r in a:
for b in r:
c += str(b)
c += '\n'
return c
But note that appending to a string is very inefficient, as it ends up creating lots of intermediary strings. Usually, you would create a list instead to which you append your string parts, and then finally join that list to convert it to a single string:
c = []
for r in a:
for b in r:
c.append(str(b))
c.append('\n')
return ''.join(c)
And then, you can also use list expressions to make this shorter in multiple steps; first for the inner list:
c = []
for r in a:
c.extend([str(b) for b in r])
c.append('\n')
return ''.join(c)
And you can join that list comprehension first:
c = []
for r in a:
c.append(''.join([str(b) for b in r]))
c.append('\n')
return ''.join(c)
Then you can move the newline into the outer join, and make a new list comprehension for the outer list:
c = [''.join([str(b) for b in r]) for r in a]
return '\n'.join(c)
And at that point, you can make it a one-liner too:
return '\n'.join([''.join([str(b) for b in r]) for r in a])
As Padraic pointed out in the comments, joining on the newline character will also prevent the string from having a trailing \n which you would end up if you kept adding it in the loop. Otherwise, you could have used str.rstrip('\n') to get rid of it afterwards.