I have a dictionary in Python 3 in which all key-value pairs have the following structure:
my_dict = {'Jerry': [0.4, 'Queens', 0.6, 'Knicks']}
This means that the value is always a list with float, string, float, string.
I need to modify the values so that the two floats are averaged, and that the new dictionary looks as follows:
new_dict = {'Jerry': [0.5, 'Queens', 'Knicks]}
I have tried a for loop that selects the floats from the value list based on their indexes, but Python doesn't let me index through it.
for k, v in my_dict.items():
average = sum(v[0], v[1])/2
my_dict[k] = [average, v[1], v[3]]
This returns
TypeError: 'float' object is not iterable
How could I select the floats to work out the average?