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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T16:24:38+00:00 2026-05-25T16:24:38+00:00

Working in Python 2.7. I have a dictionary with team names as the keys

  • 0

Working in Python 2.7.

I have a dictionary with team names as the keys and the values are contained in lists. The first value is the amount of runs the team scored, the second is runs allowed:

NL = {'Phillies': [662, 476], 'Braves': [610, 550], 'Mets': [656, 687]}

I have a function that iterates over each key and provides the total runs scored and allowed for the dictionary as a whole. I would also like to be able to subtract each individual team from the total, and create a league minus team value.

I first tried something along the lines of this:

def Tlog5(league, league_code):
    total_runs_scored = 0
    total_runs_allowed = 0
    for team, scores in league.iteritems():
        total_runs_scored += float(scores[0])
        total_runs_allowed += float(scores[1])
        team_removed_runs = total_runs_scored - scores[0]

Unfortunately, that appeared to be subtracting from only the values that had already been iterated instead of the complete total. So, for the first team in the dictionary, team_removed_runs was 0, for the second team it was the the total runs for of the first two teams minus the second teams total (leaving only the first teams total.

I tried to move the team_removed_runs = total_runs_scored – scores[0] out of the for loop, but then I only got a value for the last team in the dictionary.

Is there a way I can return the team_removed runs for all the teams in the dictionary?

Thanks for any 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-25T16:24:38+00:00Added an answer on May 25, 2026 at 4:24 pm

    If you want the team_removed_runs for every team in the dictionary, you’ll need to go back through the dictionary and compute the total number of runs minus the runs for each team. Something like

    team_removed_runs = {}
    for team, scores in league.iteritems():
        team_removed_runs[team] = [total_runs_scored - scores[0],
                                   total_runs_allowed - scores[1]]
    

    This will use the final values of total_runs_scored and total_runs_allowed for the entire league, and then subtract each teams values from that total, storing the result in the dictionary team_removed_runs. So if you wanted the value for the league total less the Phillies, you could find this at

    team_removed_runs['Phillies']
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Working in Python 2.7. I have a dictionary with team names as the keys
I'm working on my first object oriented bit of python and I have the
Working in python 2.7. I have two lists (simplified to make explanation more clear):
Working in python 2.7. I have two lists (simplified to make explanations clearer). T
Working in Python 2.7. I have two different lists, A and B (simplified to
I have recently been working with Python using Komodo Edit and other simpler editors
I need to have an at-home project now that I'm working on Python/Django at
I am working with Google App Engine and Python. I have a model with
I'm wondering if anyone have a good resource for working with Corba in Python?
Possible Duplicate: Sort by key of dictionary inside a dictionary in Python I have

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.