Reputation: 13
def matrixflip(myl,c):
if(c=='v'):
myl=myl[::-1]
return myl
elif(c=='h'):
myl=myl[::][::-1]
return myl
else:
return myl
myl=[[1, 2], [3, 4]]
print(matrixflip(myl,'h'))
In the above code I'm calling the matrixflip() function to flip the rows of list/ flip the 2d matrix horizontally by passing the second argument as 'h'. However, i still get the vertically flipped version.
Upvotes: 1
Views: 1312
Reputation: 311723
You need to reverse each sublist. The easiest way to do this is probably with a list comprehension expression:
result = [x[::-1] for x in myl]
Upvotes: 1