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 6742577
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T11:51:36+00:00 2026-05-26T11:51:36+00:00

I have data in following form (saved in a list) id, price, date, category

  • 0

I have data in following form (saved in a list)

id, price, date, category

Now, I basically want to seperate items based on the category..
basically a dictionary where key is the category and rest of the stuff (id, price, data) are its values
I have already created a datastructure so lets a datastructre ‘item’ has the above four stated attributes (id, price, date, category)
So basically what i want is a dictionary in following form:

{1: [item_1,item_2....], 2:[item....]} 

how do i do this..
Since there are many values in a single key hence i know that it will use defaultdict.. but still I am not able to get around this.
Thanks

  • 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-26T11:51:37+00:00Added an answer on May 26, 2026 at 11:51 am

    I think you want something like this, assuming your current data is stored in the list list_data:

    dict_data = defaultdict(list)
    for item in list_data:
        dict_data[item.category].append(item)
    

    If each item is a tuple instead of an object, use item[3] instead of item.category.

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

Sidebar

Related Questions

I have 10GB data in the following form: A=good B=c++ Now I wish to
I have the swiss data set provided by R, which has the following form:
I have the following form <form name=myForm id=myForm method=post enctype=multipart/form-data action=script.php> and this jQuery
I have the following code I use to insert form data into a single
I have the following in jsp: <form action=/ucReady2/uploadservlet method=post enctype=multipart/form-data> <label for=filename_1>File: </label> <input
I have following Situation, Server A sends some data (HTML form) to server B,
I have following data frames > head(elo) date elo 1 1921-12-18 1597 2 1922-05-14
I have following data structure (simplified): A giant list of the class TestClass public
I have following data in my table. alt text http://img26.imageshack.us/img26/3746/productfield.png I want to extract
I have the following form on an .NET MVC View: <form method=post enctype=multipart/form-data action=/Video/UploadDocument>

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.