# convert to (movieID, (rating, 1.0))
movieRatings = lines.map(parseInput)
# Reduce to (movieID, (sumOfRatings, totalRatings))
ratingTotalsAndCount = movieRatings.reduceByKey(lambda movie1, movie2: (movie1[0]+movie2[0], movie1[1]+movie2[1]))
# Map to (movieID, averageRating)
averageRatings = ratingTotalsAndCount.mapValues(lambda totalAndCount: totalAndCount[0]/totalAndCount[1])
# sort by average rating
sortedMovies = averageRatings.sortBy(lambda x: x[1])
# take the top 10 results
results = sortedMovies.take(10)
요 녀석을 제출할 땐 spark-submit [xxxxx.py](<http://xxxxx.py>)
로 제출한다.
spark-submit
에 다양한 매개 변수를 줄 수도 있음
사용하고 싶은 클러스터나 각 executor에 얼만큼 메모리를 할당할 것인지 등등을 지정할 수 있는데, 보통은 클러스터가 이미 합리적인 값으로 구성되어 있을 것이므로, Hadoop 관리자가 아니라면 크게 신경 쓸 필요가 없음