key-value

Why will python function max() return different outputs if float('NaN') value is permuted in a dictionary but key-max_value remains the same?

Why will python function max() return different outputs if float('NaN') value is permuted in a dictionary but key-max_value remains the same? Question: Let’s pretend I have the following simple dictionary: dictionary = {‘a’:3, ‘b’:4, ‘c’:float(‘NaN’)} If I use function max() to return the key with maximum value… key_maxvalue = max(dictionary, key=dictionary.get) print(key_maxvalue) …python outputs this: …

Total answers: 2

Check a subkey value using a random variable and a condition. KeyError: "x"

Check a subkey value using a random variable and a condition. KeyError: "x" Question: I’m having trouble with the dictionary code for checking the value of a subkey. I want to get that: If random_data is a word that matches "gender": "male" then I want to print "Word is Male" If random_data is a word …

Total answers: 2

Loop through a string-list and make key:pair in json format in Python

Loop through a string-list and make key:pair in json format in Python Question: I have a csv file as: devid,1, devType,"type-928" devid,2, devType,"type-930" etc. Length of the lines might be different, depending on the number of key-pair values included. But must have ‘devid’ and ‘devType’ in them. Want to pair them as key:value and format …

Total answers: 2

How to convert string to key value in python

How to convert string to key value in python Question: I have a Django Application and want to convert a value from a string field which is comma separated to a key vaule pair and add it to a json data block. class MyClass1(models.Model): keywords = models.TextField(_(‘Keywords’), null=True, blank=True) Example of list: blue,shirt,s,summer,for women The …

Total answers: 1

Is there a way to take a key from one dictionary and add it to another?

Is there a way to take a key from one dictionary and add it to another? Question: My goal is to take a key from one dictionary which holds lots of keys and values, and add the key to an empty dictionary. The key is stored in a variable name called "bossname" all of the …

Total answers: 1

Pair files using Python

Pair files using Python Question: I have a folder with several .tif files that I would like to pair to perform some functions inside a for loop. For example: smp001_GFP.tif smp001_mCherry.tif (this should be a pair) smp002_GFP.tif smp002_mCherry.tif (this another pair) I would like the for loop to iterate over each pair and perform some …

Total answers: 3

how I can print the values of a dictionary?

how I can print the values of a dictionary? Question: hello every one I’m trying to check a key in a dictionary and print it’s value as output. but it pass the item and nothing won’t happen. I write this code: dict1={ "apple":130, "avocado":50, "banana":110, "cantaloupe":50, "grapefruit":60, "grapes":90, "honeydew melon":50, "kiwifruit":90, "lemon":15, "lime":20, "nectarine":60, "orange":80, …

Total answers: 3

How to change a specific value of a specific key in text file using python

How to change a specific value of a specific key in text file using python Question: I would like to know how to replace a value of a specific key in a text file using python I have this text file named passenger.txt have the following: {‘Civil ID’:’1′, ‘Name’:’Mike’, ‘DOB’:’12/2/2000′, ‘Gender’:’Male’, ‘Customs fine’:”, ‘Status’:”} I …

Total answers: 5

Add values for keys that contains similar string in python

Add values for keys that contains similar string in python Question: I have dict as values={‘P-ETH-900′:Decimal(122),’P-ETH-700′:Decimal(455),’P-BTC-900′:Decimal(12),’P-BTC-700’:Decimal(55)} I want to add the decimals that has condition like eth=Decimal(0) for i,j in values.items(): if ‘ETH’ in i: eth=eth+j So basically, for each similar items , need to sum up the decimal values. output: {‘ETH’:’577′,’BTC’:’67’} Asked By: Madan …

Total answers: 1

How to check if list element in a dictionary is the same as the key in a dictionary and then print the value of the key with the list element

How to check if list element in a dictionary is the same as the key in a dictionary and then print the value of the key with the list element Question: recipedict = {‘sandwich’:[‘a buttered sandwich’,[[‘bread’,’13’],[‘butter’,’4′]]]} supplydict = {‘bread’:[‘150′,’15’,’james’],’butter’:[’15’,’12’,’allen’],’sugar’:[’15’,’12’,’marc’]} supplierdict = {"james":’12345234′,"allen":’17682342′} for example I have these 3 dictionaries. I need to check if the …

Total answers: 1