This also works:
pairs = dict([tuple(namn[i:i+2]) for i in range(0, len(namn), 2)])
for name, age in sorted(pairs.items()):
print("%s: %d" % (name, age))
avg_age = sum(pairs.values())/ len(pairs)
print("Average Age: %f" % (avg_age))
Output:
Anna: 27
Emelie: 32
Erik: 30
Johanna: 29
Jonas: 26
Josefine: 20
Kalle: 23
Lena: 22
Peter: 19
Average Age: 25.333333
You could also extend this by sorting the names in alphabetical order too.
2
solved Print a list with names and ages and show their average age