use enumerate:
for column, value in enumerate(row):
pyTony
pyMod
6,299 posts since Apr 2010
Reputation Points: 879
Solved Threads: 986
Skill Endorsements: 26
What have the values to do it. Give example how it does no work and what you would like to get instead.
pyTony
pyMod
6,299 posts since Apr 2010
Reputation Points: 879
Solved Threads: 986
Skill Endorsements: 26
Your pseudo code is cryptic. In the 2 first ifs, row seems to be an integer, then in the else part it's an iterable, and you don't say what 'the first in row' and 'the last in row mean'. Could you give an example of what the row variable contains and what you are searching in this value ?
Gribouillis
Posting Maven
3,101 posts since Jul 2008
Reputation Points: 1,130
Solved Threads: 761
Skill Endorsements: 11
Looks similar to pascal triangle, maybe you could adapt this code, I do not however use any indexes:
pascal = []
row = []
for count in range(int(input('Height of triangle: '))):
new_row = []
prev = 0
for val in row:
new_row.append(val+prev)
prev = val
new_row.append(1)
row = new_row
print row
pascal.append(row)
pyTony
pyMod
6,299 posts since Apr 2010
Reputation Points: 879
Solved Threads: 986
Skill Endorsements: 26
You have to know what you are coding before you can write the code. What solution are you trying to write. Just throwing code against the wall to see what sticks doesn't work. If you draw it out, it becomes somewhat clear.
Hint: it has to do with the length being odd or even.
woooee
Posting Maven
2,703 posts since Dec 2006
Reputation Points: 827
Solved Threads: 779
Skill Endorsements: 9