I'm trying to sort a 3D array and having little success. I have read various methods on how this is done for two dimensions, but I can't seem to scale it up.
example array:
r =[[['steve',1, 40], ['steve',3, 20], ['steve',2, 30]],
[['john',5, 50], ['john',6, 40], ['john',4, 30]]]
I want this to be sorted by the second value, so that it would return:
steve 1 40
steve 2 30
steve 3 20
john 4 30
john 5 50
john 6 40
I have tried this method with itemgetter, but it doesn't seem to work.
from operator import itemgetter
r =[[['steve',1, 40], ['steve',3, 20], ['steve',2, 30]],
[['john',5, 50], ['john',6, 40], ['john',4, 30]]]
sorted_r = sorted(r, key=itemgetter(1))
print sorted_r
Thanks.