I have a dictionary of dictionaries which hold list of tuples like this: I would like to calculate the delta of the third items (which their first two items are identical) in each tuple inside of the dictionaries, between each week (e.g., week1 and week2,.. week19 and week20)and put them as new dictionaries i…
Tag: dictionary
Create a list of dictionaries from nested list
I do have a dynamic text that will change. I want to store those values in a meaningful way. I have created a nested list to store them but I need to convert those to individual dictionaries and store it into a list. How do I do this? So far good. Devices variable is a nested list. I need to
How to create a two-level-dictionary from one file?
I have a csv file that looks like this (in reality it is bigger): How could I read this file the easiest, so that I could get a dictionary like this (dictionaries inside a dictionary): I first tried to make a separate list from the first of the file, aka from the companies, then created a dictionary from them…
How to split a dictionary based on similarity of values into two separate dictionaries
I have a dict: and I want to split it such that one dict contains all items with value == ‘a’ and the other one all items with value == ‘b’: How can I do this in an short way? My approach does not work. Answer Try this instead: In your original code, you were recreating dict_a or dict_…
How To Recurisve JSON file without any loop (like:for,while,etc) in Python
I’m confuse how to create recursive function to print JSON file without any loops in Python3. So i have home work from my college, the subject is about recursion in function, the lecturer told me to to use recursion only instead of loops. My json file in Category.json is: My python code is: I’m no…
Assigning keys and storing in a dictionary Python
For an event of rolling a six-sided die. I need to randomly simulate the event 1000 times and plot a histogram of results for each number on the dice. I want to assign the results for each number to a key of the same value (1 for number of 1s{1:164…}). I need help assigning keys and storing everyting in…
Best practice/way to get value where id = something on a list of dictionaries
I have the following list of dictionaries: I would like to get the value where id = xxxxxxxxxxxx. Which would be the fastest way? Answer One possible solution is to use next() built-in method: Prints: Or: If you search multiple times, it’s worth considering transforming the list to dictionary:
Most efficient way to get a key from a dictionary
Let d be a large (but still fits into memory) Python dictionary where we do not know what the keys are. What is the most efficient way (efficient should mean something like the memory used to perform the task is small compared to the size of the dictionary and the speed should at least as fast any of the meth…
Python: Create a list in which each element is a list with a name
before you all tell me to search for stuff, let me tell you “I HAVE”. I have searched quite a bit. Forums, educational/training sites, stackexchange and all the regulars. I haven’t been able to get what I need. I am not running to SE at the first sign of trouble either. I have registered on …
How to combine line by line dictionary into one?
I currently have a line by line dictionary: Is there a way to turn this into a one line dictionary? The outcome I would like: I’m new to Python and a little lost how to do it to a dictionary. Answer Based on the comments, here is version that reads lines from a file and converts them to one dictionary: