I'm not sure if I am asking the question in the right way, but this is my issue:
I have a list of dicts in the following format:
[
{'user': 'joe', 'IndexUsed': 'a'},
{'user': 'joe', 'IndexUsed': 'a'},
{'user': 'joe', 'IndexUsed': 'a'},
{'user': 'joe', 'IndexUsed': 'b'},
{'user': 'admin', 'IndexUsed': 'a'},
{'user': 'admin', 'IndexUsed': 'c'},
{'user': 'hugo', 'IndexUsed': 'a'},
{'user': 'hugo', 'IndexUsed': 'd'},
...
]
I want my final result to look like this:
[
{'user': 'joe', 'IndexUsed': ['a', 'b']},
{'user': 'admin', 'IndexUsed': ['a', 'c']},
{'user': 'hugo', 'IndexUsed': ['a', 'd']},
]
In essence, combining/deduplicating the unique fields in IndexUsed
and reducing them to only one dict per user
I have looked into using reducers, dict comprehension, and searched on StackOverflow but I have some trouble finding use cases using strings. The majority of examples I have found are using integers to combine them into a final int/float, but here I rather want to combine it into a single final string. Could you help me understand how to approach this problem?
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…