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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T04:24:12+00:00 2026-06-09T04:24:12+00:00

Possible Duplicate: How to calculate the occurrences of a list item in Python? I

  • 0

Possible Duplicate:
How to calculate the occurrences of a list item in Python?

I am making a sort of poll. For that, I am using Python, and the part I am stuck at is trying to figure out how to count the number of times a certain thing, say, “General Store” shows up.

E.g. of Poll:

Where do you see advertisements the most?

  1. General Store

  2. Supermarket

  3. Mall

  4. Small Stores

The poll data is submitted via radio buttons if that information is needed. All of these answers would be appended to a list, and then I want to create a results page that shows how many times each thing was voted on.

  • 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-06-09T04:24:15+00:00Added an answer on June 9, 2026 at 4:24 am

    first of all, I’m going to say you’re probably using the wrong sollution for your poll results problem. Why not keep a counter for each option, this way, your file, or whatever backend you’re using to store this data won’t grow linearly as responses come in.

    The reason that would be easier, is because you’ll be creating counters anyway, with the only difference here that you’ll have to count all the items every time the responses page is loaded.

    #initializing a variable with some mock poll data
    option1 = "general store"
    option2 = "supermarket"
    option3 = "mall"
    option4 = "small store"
    
    sample_data = [option1,option2,option1,option1,option3,option3,option4,option4,option4,option2]
    
    #a dict that will store the poll results
    results = {}
    
    for response in sample_data:
        results[response] = results.setdefault(response, 0) + 1
    

    now, results will have every string that occurred in the list as a key, and the number of times it occurred as it’s value.

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

Sidebar

Related Questions

Possible Duplicate: how to calculate difference between two dates using java I'm trying something
Possible Duplicate: How to calculate the difference between two dates using PHP? I have
Possible Duplicate: How to calculate the difference between two dates using PHP? When a
Possible Duplicate: How to calculate the difference between two dates using PHP? how can
Possible Duplicate: How to calculate the difference between two dates using PHP? I have
Possible Duplicate: How to calculate the difference between two dates using PHP? I have
Possible Duplicate: How to calculate or approximate the median of a list without storing
Possible Duplicate: C programming division I'm trying to calculate the period of accelerometer updates
Possible Duplicate: How to calculate speed of our car using iphone How can I
Possible Duplicate: How to calculate the difference between two dates using PHP? How to

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.