x = [1,2,6,9,7,7,1]
def closest_to_average(lst):
""" Busca na lista o valor mais próximo da média.
Parâmetros:
lst list: Lista de números a ser verificada.
Retorno:
numérico: Valor mais próximo da média.
"""
avg = sum(lst) / len(lst)
diffs = {value: abs(value - avg) for value in lst}
return min(diffs, key=diffs.get)
print(closest_to_average(x))
eCA9IFsxLDIsNiw5LDcsNywxXQoKZGVmIGNsb3Nlc3RfdG9fYXZlcmFnZShsc3QpOgogICAgCiAgICAiIiIgQnVzY2EgbmEgbGlzdGEgbyB2YWxvciBtYWlzIHByw7N4aW1vIGRhIG3DqWRpYS4KICAgIAogICAgUGFyw6JtZXRyb3M6CiAgICAgICAgbHN0IGxpc3Q6IExpc3RhIGRlIG7Dum1lcm9zIGEgc2VyIHZlcmlmaWNhZGEuCiAgICAgICAgCiAgICBSZXRvcm5vOgogICAgICAgIG51bcOpcmljbzogVmFsb3IgbWFpcyBwcsOzeGltbyBkYSBtw6lkaWEuCiAgICAiIiIKICAgIAogICAgYXZnID0gc3VtKGxzdCkgLyBsZW4obHN0KQogICAgZGlmZnMgPSB7dmFsdWU6IGFicyh2YWx1ZSAtIGF2ZykgZm9yIHZhbHVlIGluIGxzdH0KICAgIAogICAgcmV0dXJuIG1pbihkaWZmcywga2V5PWRpZmZzLmdldCkKICAgIApwcmludChjbG9zZXN0X3RvX2F2ZXJhZ2UoeCkp