Query about brackets in python


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:

 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
  return distances

Could you tell me what the two brackets [0][1] do, then this sentence?

nearest = computeNearestNeighbor(username, users)
asked by naveganteX 12.12.2018 в 13:02

0 answers