Considering you have a list of dictionaries with different elements e.g:
{
"acousticness": 0.0681,
"energy": 0.724,
"loudness": -5.941,
"tempo": 132.056,
"valence": 0.676
},
{
"acousticness": 0.2754,
"energy": 0.866,
"loudness": -7.874,
"tempo": 180.056,
"valence": 0.540
},
{
"acousticness": 0.0681,
"energy": 0.724,
"loudness": -5.941,
"tempo": 132.056,
"valence": 0.676
}
And you give the user the ability to enter a dictionary themselves e.g.
{
"acousticness": 0.1382,
"energy": 0.7274,
"loudness": -5.8246,
"tempo": 122.6412,
"valence": 0.6153
}
How would you iterate through the dictionary in Python3 to get the closest dictionary back?
I found this explanation on how to find the nearest element in a normal array but can't get around how to do the same with array comparison.
Thanks for any help in advance!