I have two dictionaries named as, lets say, a = {‘A’:{2021:45.65},’B’:{2021:56.34}} and b = {‘A’:{2021:78.67},’B’:{2021:87.54}} I want to get the values from both A and B ‘sub-dictionaries’ and compute what percentage of value from the second dictionary is the value from the first dictionary. I can’t seem to figure out a way how to access both the float values from
Tag: dictionary
How to delete values in a dict based on the presence of child values
I have a dict that looks like this: How can I iterate over the elements of this dict, and exclude any element that has “‘parent’ : None” and no child element (meaning, no other element in this dict has this one as a parent). Expected output: Answer I think this function can help you To use it:
How to use dictionary in oop to store data
i want to ask you i want to store all informations in dictionary for this code but i can’t i know that something i did wrong.I like to store informations from Customers if issue take a hourly , monthly or daily it is on BikeRental request bikes what i tried by far is any way? Answer If you just wanted
Dictionary making weird key:value pairs
I want to make a simple calculator, where you just type in something like “2+2*2” and it calculates the answer. First step was to find, and cut out the individual numbers, which I tried doing below. But when I input: I don’t get the expected output of: But rather: I’m still very new to python, so please also tell me
How to search by dict keys in ElasticSearch
I am new in elasticsearch and I need to write query described below I have an elasticsearch index with documents like this one Numbers mean entries of words in book I want to search documents by words “cats” (not “cat”), “monkey” and e.g “mous”. How do I write query that will find “cat”, “monkey” and “mouse” in document and consider
Convert a Pandas DataFrame with true/false to a dictionary
I would like to transform a dataframe with the following layout: into a dictionary with the following structure: Answer IIUC, you could replace the False to NA (assuming boolean False here, for strings use ‘false’), then stack to remove the values and use groupby.agg to aggregate as list before converting to dictionary: output:
function that pairs keys of two dictionaries based on how close their values are?
I want to make a function that takes two dictionaries as inputs, where the keys of the dictionaries are strings and the values are ints or floats. It should only use list comprehensions, for-loops, and if statements without imports. for example, an input should look like this: the goal of this function is to return a single new dictionary comprised
Usage of a dictionary, Right or wrong?
I’m creating a car sales program and need to use a dictionary, I have a basic understanding of them. Would it be efficient to hold the car name as a string for the key, then store the relevant cars selling price in the values through a list? for example, Can this work? Is there a better usage for the dictionary?
How to remove array from values in a dictionary
I have the following dictionary But I’d like to remove the lists so it looks like this: Is there a simple way to do this? I think I might be able to iterate through and remove the list. Thanks Answer In order to produce the required output you will need a list (set) of keys that should not be modified.
Python: Safe dictionary access with lists?
Is there an exception free way to access values from a dictionary containing lists. For example, if I have: How do I access the path data[‘object_1’][‘object_2’][‘list’][0][‘property’] safely(i.e. return some default value if not possible to access without throwing error)? I am trying to avoid wrapping these in try-except’s. I have seen the reduce based approach but it doesn’t take into