Given lists as follows:
make = ['ford', 'fiat', 'nissan', 'suzuki', 'dacia']
model = ['x', 'y', 'z']
version = ['A', 'B', 'C']
typ = ['sedan', 'coupe', 'van', 'kombi']
infos = ['steering wheel problems', 'gearbox problems', 'broken engine', 'throttle problems', None]
total.append(make)
total.append(model)
total.append(version)
total.append(typ)
total.append(infos)
I need to create list of lists of all possible combinations of these lists so I did:
combos = list(itertools.product(*total))
all_combos = [list(elem) for elem in combos]
Now I want to compare, find in a JSON object items with the same set of values as occurs in item of all_combos and count number of these occurences. My JSON is large and looks a bit like:
data = [
{ 'make': 'dacia'
'model': 'x',
'version': 'A',
'typ': 'sedan',
'infos': 'steering wheel problems'
}, ...]
I want to get output like:
output = [
{ 'make': 'dacia'
'model': 'x',
'version': 'A',
'typ': 'sedan',
'infos': 'steering wheel problems',
'number_of_occurences_of_such_combination_of_fields_with__such_values': 75
}, ...]
How to resolve such task?