Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4021002
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T10:17:53+00:00 2026-05-20T10:17:53+00:00

I have a list that contains many dictionaries. Each dictionary represents a change that

  • 0

I have a list that contains many dictionaries. Each dictionary represents a change that has occurred within my application. The “change” dictionary has the following entries:

userid: The user ID for a user
ctype: A reference to a change type in my application
score: A score

The ctype can be one of about 12 different strings to include “deletion”, “new”, “edit” and others. Here is an example of one of the “change” dictionaries:

{'userid':2, 'score':10, 'ctype':'edit'}

My question is, how can I create a dictionary that will aggregate all of the change types for each user within this large list of dictionaries? I would like to add the score from each change dictionary to create a total score and add each ctype instance together to get a count of each instance. The goal is to have a list of dictionaries with each dictionary looking like this:

{'userid':2, 'score':325, 'deletion':2, 'new':4, 'edit':9}

I have been trying to work this out but I am pretty new to python and I wasn’t sure how to count the actual change types. The other part that gets me is how to refer to a dictionary based on ‘userid’. If someone can present an answer I am sure that all of this will become very apparent to me. I appreciate any and all help.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T10:17:54+00:00Added an answer on May 20, 2026 at 10:17 am

    The key thing to agregate data here is to have a dictionary where each key is the userid, and each entry is the data relevant to that userid.

    final_data = {}
    for entry in data:
        userid = entry["userid"]
        if userid not in final_data:
            final_data[userid] = {"userid": userid, "score": 0} 
        final_data[userid]["score"] += entry["score"]
        if not entry["ctype"] in final_data[userid]:
            final_data[userid][entry["ctype"]] = 1
        else:
            final_data[userid][entry["ctype"]] += 1
    

    If you want the result as a list of dictionaries, just use final_data.values()

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a div that contains many spans and each of those spans contains
I have a list that contains many objects.I want found an object in this
I have a List that contains items, for example: 1) https:\\10.12.23\\ 2) https:\\12.23.12.25\\ 3)
I have a list box control that contains enough items to list them with
I have a PersonEditorModel that contains a list of people that I want represented
I have a Silverlight 2.0 DataGrid that contains a list of items that needs
I have a ViewModel class that contains a list of points, and I am
I have a text file that contains a list of filenames, minus the extension,
I have a RecipeJDO that contains a List< IngredientJDO >. RecipeJDO owns the ingredients.
I have a text document that contains a list of numbers and I want

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.