I am trying to group the self.L list into groups of five and then reverse both individual groups I want my output to look as follows
step1.(group the list into two section of five)
[[1,3,5,67,8],[90,100,45,67,865]]
step2.(reverse the numbers within the two groups)
[[8,67,5,3,1],[865,67,45,100,90]]
The code I have
class Flip():
def __init__(self,answer):
self.Answer = answer
self.matrix = None
self.L = [1,3,5,67,8,90,100,45,67,865,]
def flip(self):
if self.Answer == 'h':
def grouping(self):
for i in range(0, len(self.L), 5):
self.matrix.append(self.L[i:i+5])
print(self.matrix)
if __name__ =='__main__':
ans = input("Type h for horizontal flip")
work = Flip(ans)
work.flip()
When I run the code my output is
None
self.matrix = Noneis going to give you problems based on how you are using it. You seem to want to use this as a list, so just initialize it as one:self.matrix = []groupinginside theflipmethod (a closure), but 1/ you don't callgrouping(), nor do you return any result fromgrouping. So you just print the still empty matrix.