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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T05:19:06+00:00 2026-06-13T05:19:06+00:00

I have a dictionary in the form: {a: (1, 0.1), b: (2, 0.2), …}

  • 0

I have a dictionary in the form:

{"a": (1, 0.1), "b": (2, 0.2), ...}

Each tuple corresponds to (score, standard deviation).
How can I take the average of just the first integer in each tuple?
I’ve tried this:

for word in d:
    (score, std) = d[word]
    d[word]=float(score),float(std)
    if word in string:
        number = len(string)
        v = sum(score)
        return (v) / number

Get this error:

    v = sum(score)
TypeError: 'int' object is not iterable
  • 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-13T05:19:08+00:00Added an answer on June 13, 2026 at 5:19 am

    It’s easy to do using list comprehensions. First, you can get all the dictionary values from d.values(). To make a list of just the first item in each value you make a list like [v[0] for v in d.values()]. Then, just take the sum of those elements, and divide by the number of items in the dictionary:

    sum([v[0] for v in d.values()]) / float(len(d))
    

    As Pedro rightly points out, this actually creates the list, and then does the sum. If you have a huge dictionary, this might take up a bunch of memory and be inefficient, so you would want a generator expression instead of a list comprehension. In this case, that just means getting rid of one pair of brackets:

    sum(v[0] for v in d.values()) / float(len(d))
    

    The two methods are compared in another question.

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

Sidebar

Related Questions

I have a dictionary named 'score' with keys that are tuples. Each tuple is
I have a dictionary-tree in an non-standard form like so: tree = {'0': {'A':
I have a data in form a dictionary.. NOw I take the input from
I have some data in this form (dictionary): Value0 Text1 Value1 Text2 Value2 Text3
I have a dictionary, user_dict, and create a list for each user value, this
I have a dictionary with tuples as keys. e.g.: {('tags','1'): 'name', ('name','first'):'rik', ('name','last'):'atee'} In
I have a dictionary in JSON form, like this: $user = { name: Mary
I have two complex dictionaries in the form Dictionary<string, Dictionary<string, Dictionary<string, List<string>>>> So as
I have a form where users can enter data that ultimately would be used
I have form, where user selects Airport and then can select one of airport

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.