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

  • Home
  • SEARCH
  • 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 9171825
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T16:12:57+00:00 2026-06-17T16:12:57+00:00

This is basically what I’m attempting to do, which isn’t working. Is there a

  • 0

This is basically what I’m attempting to do, which isn’t working. Is there a way to single out a value of the dictionary and mathify it? For the sake of a crap example:

dictionaryNumbers = {'a':10,'b':10,'c':1,'d':1,'e':5,'f':1}
dictionaryNumbers['a'] += 5
#The goal would be dictionaryNumbers['a'] would equal 15.

EDIT:

Guys thanks for the feedback. It seems there was a flaw in the order in which I was calling the functions to modify the collection. I was printing the output before the math took place. Thanks again.

  • 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-17T16:12:58+00:00Added an answer on June 17, 2026 at 4:12 pm

    You are mostly doing it right, and your code is working fine:

    >>> dictionaryNumbers = {'a':10,'b':10,'c':1,'d':1,'e':5,'f':1}
    >>> dictionaryNumbers['a'] += 5
    >>> dictionaryNumbers['a']
    15
    

    but for any key not yet in the dict you’d have to test first (if key not in dictionaryNumbers) or use .get():

    >>> dictionaryNumbers['z'] = dictionaryNumbers.get('z', 0) + 3
    

    which gets old fast.

    But I’d use a collections.Counter() class instead:

    >>> from collections import Counter
    >>> counter = Counter()
    >>> counter.update({'a':10,'b':10,'c':1,'d':1,'e':5,'f':1})
    >>> counter
    Counter({'a': 10, 'b': 10, 'e': 5, 'c': 1, 'd': 1, 'f': 1})
    >>> counter['a'] += 5
    >>> counter['a'] 
    15
    >>> counter.most_common(3)
    [('a', 15), ('b', 10), ('e', 5)]
    

    Advantages:

    • No need to test for new keys; accessing a nonexisting key automatically assigns a count of 0
    • Creating a new counter from a list of items to count is as easy as Counter(items_to_count).
    • You can sum counters; counter1 + counter2 returns a new Counter with all values summed.
    • You can subtract counters (negative values are removed), intersect them (find the minimum of either count), or create a union (maximum counts).
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

So basically this code was working fine before. I had some computer issues and
I have an ajax function which looks like this (basically, it's simplified): function getPage(targetURL,
Basically this is a button existing out of rectangle and several textblocks. The rectangle
The layout looks like this: Basically all I want is to find out if
As of dotCover 2.0, there is support for attribute filters. This basically allows you
My document looks like this: Basically the background is one full-screen, transparent div. There
I'm sure someone will help with this: Basically I got a form which on
I am trying to to build a Felix bundle in Eclipse. This basically includes
This code basically translates characters based on position in one string to the character
This is basically a math problem, but very programing related: if I have 1

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.