I'm using python dictionaries from counting the repeated objects from an array. I use a function obtained from this forum from counting the objects, and the obtained result is on the next format: {object: nºelements, ...). My issue is that the function doesn't return the dictionary objects differentiated by keys and I don't know how to get the objects.
count_assistence_issues = {x:list(assistances_issues).count(x) for x in list(assistances_issues)}
count_positive_issues = {x:list(positive_issues).count(x) for x in list(positive_issues)}
count_negative_issues = {x:list(negative_issues).count(x) for x in list(negative_issues)}
print(count_assistence_issues)
print(count_positive_issues)
print(count_negative_issues)
This is the output obtained:
{school.issue(10,): 1, school.issue(13,): 1}
{school.issue(12,): 1}
{school.issue(14,): 2}
And this is the output I need to obtain:
{{issue: school.issue(10,), count: 1},
{issue: school.issue(13,), count: 1}}
{{issue: school.issue(12,), count: 1}}
{{issue: school.issue(14,), count: 2}}
Anyone know how to differenciate by keys the elements of the array using the function? Or any other function for counting the repeated objects for obtaining a dictionary with the format {'issue': issue,'count': count) Thanks for reading!
list
conversions andcount
ing each time... So you should look to change those tocount_assitence_issues = collections.Counter(assistances_issues)
list
ofdict
s as your current output shows you want aset
ofdict
s and sincedict
s aren't hashable - you can't do that...whatever[key]
on the object you have?