Skip to content
Advertisement

Tag: dictionary

Performing mathematical operations on values from two dictionaries with same keys in Python

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

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

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

Advertisement