8. DEVELOP A MAPREDUCE PROGRAM TO FIND THE TAGS ASSOCIATED WITH EACH MOVIE BY ANALYZING MOVIELENS DATA

with Each Movie by Analyzing MovieLens Data
Python Program:
n=int(input("Enter number of records: "))
data=[]
print("Enter UserID,MovieID,Tag:")
for i in range(n):
data.append(input().split(","))
# MAP
mapped=[]
for record in data:
movie_id=record[1]
tag=record[2]
mapped.append((movie_id,tag))
# SHUFFLE AND SORT
grouped={}
for movie_id,tag in mapped:
if movie_id not in grouped:
grouped[movie_id]=[]
grouped[movie_id].append(tag)
# REDUCE
result={}
for movie_id,tags in grouped.items():
result[movie_id]=", ".join(tags)
print("Output:")
for movie_id,tags in result.items():
print(movie_id,tags)
Input:
Enter number of records: 6
Enter UserID,MovieID,Tag:
1,101,Action
2,101,Adventure
3,101,Sci-Fi
4,102,Comedy
5,102,Family
6,103,Romance
Output:
101 Action, Adventure, Sci-Fi
102 Comedy, Family
103 Romance
