Taking into account the following code:
def recommend(username, users):
nearest = computeNearestNeighbor(username, users)[0][1]
recommendations = []
neighborRatings = users[nearest]
userRatings = users[username]
for artist in neighborRatings:
if not artist in userRatings:
recommendations.append((artist,neighborRatings[artist]))
return recommendations
The computer codeNearestNeighbor:
def computeNearestNeighbor(username,users):
"""creates a sorted list of users based on their distance to username"""
distances = []
for user in users:
if user!=username:
distance = manhattan(users[user],users[username])
distances.append((distance, user))
# Sort based on the distance -- closest first
distances.sort()
return distances
Could you tell me what the two brackets [0][1]
do, then this sentence?
nearest = computeNearestNeighbor(username, users)