def degree_of_item(train):
  """Calculates degree of items from user-item pairs."""
  item_to_deg = {}
  for pair in train:
    _, item = pair
    if item in item_to_deg:
      item_to_deg[item] += 1
    else:
      item_to_deg[item] = 1
  return item_to_deg