Title: How to group these base on same address?
Tags: python;django
Question: ```{'street_number': '3', 'street_name': 'Raycraft', 'street_type': 'Dr', 'municipality': 'Amherstview', 'postal_code': 'K7N1Z1', 'type_of_reports': 'Valuation'},
{'street_number': '3', 'street_name': 'Raycraft', 'street_type': 'Dr', 'municipality': 'Amherstview', 'postal_code': 'K7N1Z1', 'type_of_reports': 'Inspection'}
```
Group these values by address ?
for example output should be like:
```{'street_number': '3', 'street_name': 'Raycraft', 'street_type': 'Dr', 'municipality': 'Amherstview', 'postal_code': 'K7N1Z1', 'type_of_reports': ['Valuation',Inspection]}
```

Comment: it is a queryset for django. i need to convert it like in another format.

Comment: type of reports are coming together

Comment: I dont understand the question. Also, is this a dictionary? json? xlm?

Comment: I dont understand the difference between the set and expected output.


Here is another answer: I assume each of those keys is a field name in a model somewhere. If you want to do this directly in the template you might be able to use regroup
In your model add a property that is a string of all the info you want to group on:
```@cached_property
def id_str(self):
    return f'{self.street_number} {self.street_name}, {self...}'#add all fields you wish to group by
```
Then in your view add a queryset of the model to the context and in the template regroup on this property (assume the context object is called queryset):
```{% regroup queryset by id_str as regrouped_queryset %}
<ul&gt;
  {% for address in regrouped_queryset %}
    <li&gt;{{ address.grouper }}</li&gt;
      <ul&gt;
        {% for each in address.list %}
          <li&gt;{{ each.type_of_reports }}</li&gt;
        {% endfor %}
      </ul&gt;
    </li&gt;
  {% endfor %}
</ul&gt;
```

Comment for this answer: i tried your but it is not giving as output seems.
Comment for this answer: What was the output?

{'source': 'StackExchangeDataset', 'subset': 'stackoverflow.com', 'metadata': {'AnswerCount': 1, 'CommentCount': 4, 'ContentLicense': 'CC BY-SA 4.0', 'CreationDate': '2022:00:01/06/22', 'FavoriteCount': None, 'PostTypeId': 1, 'Tags': '<python><django>', 'Title': 'How to group these base on same address?', 'ViewCount': 40, 'id': 70606650, 'user_AboutMe': '<ul>\n<li>Python Software developer working currently at Neosoft Technologies. \nPursued Btech from Grahic Era University 2012-2016.</li>\n</ul>\n', 'user_AccountId': 4671220.0, 'user_DisplayName': 'winne', 'user_Reputation': 93.0, 'user_Views': 11.0, 'user_id': 3782979.0}}