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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T02:48:08+00:00 2026-05-25T02:48:08+00:00

I had a python dict like this: {‘1’ : {‘1’: {‘A’ : 34, ‘B’

  • 0

I had a python dict like this:

{'1' : {'1': {'A' : 34, 'B' : 23, 'C' : nan, 'D': inf, ...} ....} ....}

For each “letter” key I had to calculate something, but I obtained values like inf or nan and I need to remove them. How could I do that?

My first tried was to “cut” such values, i.e., to return just values between 0 and 1000 but when I did this, I got a dict with empty values:

{'1' : {'1': {'A' : 34, 'B' : 23, 'C' : {}, 'D': {}, ...} ....} ....}

perhaps there is a better solution, please help!!!!

This is part of my code, (Q and L are other dict that have the info that I need to calculate):

for e in L.keys():
  dR[e] = {}
  for i in L[e].keys():
   dR[e][i] = {}
   for l, ivalue in L[e][i].iteritems():
     for j in Q[e].keys():
       dR[e][i][j] = {}
       for q, jvalue in Q[e][j].iteritems():
         deltaR = DeltaR(ivalue, jvalue) #this is a function that I create previously
         if (0 < deltaR < 100):
           dR[e][i][j] = deltaR
  • 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-25T02:48:09+00:00Added an answer on May 25, 2026 at 2:48 am

    I’m taking a shot in the dark here, but you can probably do it in a couple of different ways. One method would be to calculate the value and then decide whether or not you actually want to keep it before sticking it into the dictionary.

    d = {}
    for letter in 'ABCDEFGHIJKLMNOPQRSTUVWXYZ':
        # I don't actually know how you're calculating values
        # and it kind of doesn't matter
        value = calculate(letter)
        if value in (inf, nan):
            continue
        d[letter] = value
    

    I’m simplifying the dictionary to only pay attention to the part of your data that actually uses letters as keys since you haven’t really given any context. That being said, I’d probably go with the first suggestion unless there’s a reason not to.

    for e in L.keys():
        dR[e] = {}
        for i in L[e].keys():
            dR[e][i] = {}
            for l, ivalue in L[e][i].iteritems():
                for j in Q[e].keys():
                    #dR[e][i][j] = {} # What's up with this?  If you don't want an empty dict,
                                     # just don't create one.
                    for q, jvalue in Q[e][j].iteritems():
                        deltaR = DeltaR(ivalue, jvalue) #this is a function that I create previously
                        if (0 < deltaR < 100):
                            dR[e][i][j] = deltaR
                    if dR[e][i][j] in (nan, inf):
                        del dR[e][i][j]
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Obs: I know lists in python are not order-fixed, but think that this one
I would like to install Python 2.5.5 to use with Google apps but have
I've had to do some introspection in python and it wasn't pretty: name =
I had an idea, if I add a python .py file to my C#
How do I call an external command within Python as if I had typed
Had a coworker ask me this, and in my brain befuddled state I didn't
I had the idea of a search engine that would index web items like
I have a string that looks like this: Name1=Value1;Name2=Value2;Name3=Value3 Is there a built-in class/function
In PHP, I had this line matches = preg_grep('/^for/', array_keys($hash)); What it would do
I have dict in Python with keys of the following form: mydict = {'0'

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.