input: Write a function to calculate the mode of a given set of values. If there are multiple modes, return the first one encountered.
  def find_mode(values):
    max_count = 0
    mode = values[0]
    counts = {}
    for value in values:
      if value in counts:
        counts[value] += 1
      else:
        counts[value] = 1
      if counts[value] > max_count:
        max_count = counts[value]
        mode = value
    return mode
  
  assert find_mode([1, 2, 3, 2, 4, 2])==2
  assert find_mode([3, 5, 3, 1, 3, 2])==3
  assert find_mode([4, 4, 3, 2, 4])==4
  assert find_mode([1, 2, 2, 2, 3, 3])==2
  assert find_mode([1])==1
output: def find_mode(values):
    max_count = 0
    mode = values[0]
    counts = {}
    for value in values:
      if value in counts:
        counts[value] += 1
      else:
        counts[value] = 1
      if counts[value] > max_count:
        max_count = counts[value]
        mode = value
    return mode