Group just the values with the same id in python

Viewed 25

I have two tables Rule and Zone, this is my Rule table which contain zone id as a foreign key :

enter image description here

I'm using this code to print the list of the values from the datatable SQLITE :

    rules_namelist = [] 
    rule = Rule.objects.all()
    for rules in rule:
        rules_entity =rules.entity 
        rules_value =rules.value    
        rules_namelist.append({rules_entity:rules_value})
    print(rules_namelist)

And I'm getting this ouuput :

[{'LOWER': 'total'}, {'TEXT': '£'}, {'LIKE_NUM': True}, {'SHAPE': 'dd/dd/dddd'}, {'LOWER': 'total'}, {'TEXT': '£'}, {'LIKE_NUM': True}, {'SHAPE': 'dd/dd/dddd'}]

I want to get just the values of the same id and print it and then get the values of the next id, Please how can I do that. Any help is highly appreciated

1 Answers
rules_namelist = [] 
rule = Rule.objects.all()
for rules in rule:
    rules_entity =rules.entity 
    rules_value =rules.value    
    rules_namelist.append({rules_entity:rules_value})
for i in rules_namelist:
    print(i)
Related