I have a RDD which looks like this.
[a, ((b, c), d)]
I tried sorting by c by the code below
sortedMovies = countRatings.sortBy(lambda x : x[1])
but it got sorted by b.
result: [(1882, ((64.5, 33.0), 1.9545454545454546)), (1499, ((52.0, 27.0), 1.9259259259259258)),(3593, ((31.5, 19.0), 1.6578947368421053)),
how can I sort it by c?
CodePudding user response:
Your lambda is pulling out ((b, c), d)
while you want it to pull out c
. Therefore:
sortedMovies = sorted(countRatings, key=lambda x: x[1][0][1])