Spaces:
Sleeping
Sleeping
File size: 1,053 Bytes
bd3532f |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
def combine_metadata_with_distance(metadatas, distances):
# Flatten the nested lists if they are nested
metadatas = metadatas[0] if isinstance(metadatas[0], list) else metadatas
distances = distances[0] if isinstance(distances[0], list) else distances
print(metadatas)
if len(metadatas) != len(distances):
raise ValueError("Number of metadata entries must match the number of distances")
combined_result = []
for metadata, distance in zip(metadatas, distances):
new_metadata = {
'title': metadata.get('title', ''),
'description': metadata.get('description', ''),
'price': metadata.get('price', ''),
'totalRatings': metadata.get('totalRatings', 0),
'reviewSummary': metadata.get('reviewSummary', ''),
'triggerWarning': metadata.get('triggerWarning', ''),
'distance': distance
}
combined_result.append(new_metadata)
combined_result.sort(key=lambda x: x['distance'])
return combined_result |