SortBy 仅在 'inner list' 中有效

SortBy only works half way in 'inner list'

我有一个看起来像这样的 RDD。

[a, ((b, c), d)]

我尝试通过以下代码按 c 排序

sortedMovies = countRatings.sortBy(lambda x : x[1])

但它按 b 排序。

result: [(1882, ((64.5, 33.0), 1.9545454545454546)), (1499, ((52.0, 27.0), 1.9259259259259258)),(3593, ((31.5, 19.0), 1.6578947368421053)),

如何按 c 排序?

您的 lambda 正在退出 ((b, c), d),而您希望它退出 c。因此:

sortedMovies = sorted(countRatings, key=lambda x: x[1][0][1])