Skip to content

Tag: dictionary

Calculate delta in dictionary of dictionary

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…

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…

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…

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…

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: