Skip to content

Commit

Permalink
fixing the example
Browse files Browse the repository at this point in the history
  • Loading branch information
seperman committed Oct 18, 2023
1 parent e586fd6 commit a9b7286
Showing 1 changed file with 8 additions and 9 deletions.
17 changes: 8 additions & 9 deletions docs/basics.rst
Original file line number Diff line number Diff line change
Expand Up @@ -235,18 +235,17 @@ group_by_sort_key is used to define how dictionaries are sorted if multiple ones
For example, there are duplicate id values. If we only use group_by='id', one of the dictionaries with id of 'BB' will overwrite the other. However, if we also set group_by_sort_key='name', we keep both dictionaries with the id of 'BB'.

Example:

[{'id': 'AA', 'int_id': 2, 'last_name': 'Nobody', 'name': 'Joe'},
{'id': 'BB', 'int_id': 20, 'last_name': 'Blue', 'name': 'James'},
{'id': 'BB', 'int_id': 3, 'last_name': 'Red', 'name': 'Jimmy'},
{'id': 'CC', 'int_id': 4, 'last_name': 'Apple', 'name': 'Mike'}]
>>> [{'id': 'AA', 'int_id': 2, 'last_name': 'Nobody', 'name': 'Joe'},
... {'id': 'BB', 'int_id': 20, 'last_name': 'Blue', 'name': 'James'},
... {'id': 'BB', 'int_id': 3, 'last_name': 'Red', 'name': 'Jimmy'},
... {'id': 'CC', 'int_id': 4, 'last_name': 'Apple', 'name': 'Mike'}]


Becomes:
{'AA': [{'int_id': 2, 'last_name': 'Nobody', 'name': 'Joe'}],
'BB': [{'int_id': 20, 'last_name': 'Blue', 'name': 'James'},
{'int_id': 3, 'last_name': 'Red', 'name': 'Jimmy'}],
'CC': [{'int_id': 4, 'last_name': 'Apple', 'name': 'Mike'}]}
>>> {'AA': [{'int_id': 2, 'last_name': 'Nobody', 'name': 'Joe'}],
... 'BB': [{'int_id': 20, 'last_name': 'Blue', 'name': 'James'},
... {'int_id': 3, 'last_name': 'Red', 'name': 'Jimmy'}],
... 'CC': [{'int_id': 4, 'last_name': 'Apple', 'name': 'Mike'}]}


Example of using group_by_sort_key
Expand Down

0 comments on commit a9b7286

Please sign in to comment.