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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T20:47:50+00:00 2026-06-01T20:47:50+00:00

I have this dictionary in which in which (key1, key2): value dict = {(‘1’,

  • 0

I have this dictionary in which in which (key1, key2): value

dict = {('1', '4'): 'A', ('3', '8'): 'B', ('4', '7'): 'C', 
('8', '9'): 'D', ('4', '2'): 'E', ('2', '0'): 'F', ('3', '9'): 
'G', ('7', '7'): 'H', ('8', '6'): 'I', ('5', '3'): 'J', 
('6', '1'): 'K'}

key1 = input('enter value of key1: ')
key2 = input('enter value of key2: ')

If I input a pair of key1, key2 and the pair doesn’t exist, is there any way that I can loop through this dictionary and pass a math function i.e. to find average value for each pair of keys and print the one that has the biggest average value?

Edit: Actually this dictionary was derived from a text file, so it has to be in string first and I need to convert it to int but I don’t know how.

  • 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-01T20:47:51+00:00Added an answer on June 1, 2026 at 8:47 pm

    Don’t call it dict, that prevents you from accessing the built-in dict.

    Your keys are strings, so there is no average value. If we convert to ints:

    dct = dict((tuple(map(int, key)), value) for key, value in str_dict.iteritems())
    

    Which gives:

    dct = {(8, 9): 'D', (4, 7): 'C', (6, 1): 'K', (7, 7): 'H', 
           (1, 4): 'A', (3, 8): 'B', (2, 0): 'F', (3, 9): 'G', 
           (4, 2): 'E', (8, 6): 'I', (5, 3): 'J'}
    

    Then you can use max on the sum of each key:

    key = max(d, key=sum)
    # (8, 9) is the key with the highest average value
    

    Since the one with the highest sum also has the highest average.

    If you then want the value for that key, it’s:

    value = dct[key]
    # 'D' is the value for (8, 9)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a Dictionary<string,string[]> Some example values are Key1 Value=1,2,3,4,5 Key2 Value=7,8 Key3 Value=null
I have an interface called Dictionary which has a method insert() . This interface
I have a list which contains a dictionary of ExpandoObjects. Im binding this to
I have this CacheManager class which keeps a static dictionary with all sorts of
I have this Class which is accepting a Dictionary<string,object> which is been invoked from
I have a list of dictionary as follows: myList=[{'id':1,'key1':'a','key2':'b'},{'id':8,'key1':'c','key2':'d'}, {'id':6,'key1':'a','key2':'p'}] To find index of
I have this dictionary in my apps model file: TYPE_DICT = ( (1, Shopping
I have this method to get a generic repository out of a dictionary: public
I have a python dictionary of type defaultdict(list) This dictionary is something like this:
I have some data in this form (dictionary): Value0 Text1 Value1 Text2 Value2 Text3

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.