So I wrote a function slanted(grid)
which takes in a grid and returns the combination of letters horizontally.
For instance, if grid
is
['q','q','d'],
['s','d','e'],
['e','g','h']
then slanted(grid)
should return
['d','qe','qdh','sg','e']
I tried to do this by writing up this code for slanted(grid)
def slanted(grid):
results = []
for j in range(len(grid)-1):
tmp = ""
for i in range(len(grid)):
tmp += [j+i][i]
results.append(tmp)
return results
print(slanted([['q','q','d'],['s','d','e'],['e','g','h']]))
but I'm getting an error message saying:
TypeError: can only concatenate str (not "int") to str
what changes to my code should I make to get the right output as indicated above?