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