So I'm trying to find diagonals on a grid. I've tried looking at some stack overflow pages that seemed to provide a clue but most of them includes itertools or numpy and a lot of built in functions.
Note: U may have seen this question somewhere else. This is basically @Bruffff's second account
So I'm just asking on behalf of all the beginners here, what's the most basic way to find all the diagonals in a given grid.
Here is what I have so far:
def columns(test):
ans = []
for x, lst in enumerate(test):
if x < len(test)-1:
ans.append(lst[x+1])
return ans
print(columns(test))
and given this grid,
test = [["r","a","w","b","i","t"],
["x","a","y","z","c","h"],
["p","q","b","e","i","e"],
["t","r","s","b","o","g"],
["u","w","x","v","i","t"]
["u","w","x","v","i","t"],
the output returns
['a', 'y', 'e', 'o', 't']
but my expected output is
[(u), (uw) (twx), (prxv), (xqsvi), (rabbit), (ayeot), (wzig), (bce),(ih), (t)]
How can I do this without using the complex built in functions and import, numpy or itertools??
I know they may be easier, but I want to learn things using the basics first, so yea, please use the most basic of approaches to do this. Thank you:)