Questions tagged [dictionary]

A dictionary, in computer science, is a data structure that maps keys to values such that given a key its corresponding value can be efficiently retrieved.

Filter by
Sorted by
Tagged with
3
votes
1answer
80 views

Add values from a dictionary to subarrays using numpy

I'm working with numpy arrays and dictionaries, the keys of the dictionary are coordinates in the numpy array and the values of the dictionary are a list of values I need to add in those coordinates, ...
2
votes
0answers
34 views

Trie to index files and search for them

Basic idea (foo and foa are filenames): ...
2
votes
1answer
61 views

Updating a dictionary of trajectories after a step has been made

I am using a dictionary to save possible trajectories in a game. A trajectory is defined as a list of numbers separated by _. For example ...
3
votes
1answer
152 views

Function takes a dictionary with list as value, returns the key of the biggest list

I created a function that takes a dictionary as parameter. This dictionary is expected to have lists as value pair. (i.e. {1: [1, 2, 3], 'a': [4, 'b', 5, 'c']} ) ...
1
vote
1answer
17 views

A structure for a text messages dictionary with system notifications/errors

I would like to arrange a system messages dictionary for an application in JavaScript. As an initial intention, I thought something about the following structure: ...
1
vote
0answers
55 views

What is the best implementation of a ignore case dictionary In C#

Imagine we have a custom dictionary class which is derived from Dictionary<string, object>. Dictionary is case-insensitive about keys and elements arrange is ...
4
votes
2answers
92 views

Replacing all keys found in a dictionary for its value in a list

I have a file that is written DOS format and I need to replace some characters into others. I created a dictionary for that purposes, and now I have to read everyline from my stream and replace my ...
1
vote
1answer
49 views

Unscramble words faster in Python

So I'm currently using python to unscramble words that are retrieved from an OCR program, and checked in the 'dictionary'. The current code I am using to unscramble words is this: ...
-2
votes
1answer
74 views

Sorting through two dictionaries [closed]

What my code try to do here is to sort items trough 2 dictionaries. If they are similar or the same, I create a new list to append them. The test file is relatively big, around 2000 data each ...
1
vote
2answers
57 views

HashMap Implementation (dictionary) in Python

I attempted making a hashmap in python, and it was harder, due to some limitations but this is my version of dictionaries in python. Are there any way to simplify or do the same thing in less code ...
-1
votes
1answer
40 views

Best way of converting a dynamic number of list items into variables in Python [closed]

I have a simple scrapy spider that crawls a page and returns H1 on the pages. Since, each page is unique, one cannot know how many h1's will be on the page. Since the scrapy spider returns a list, I ...
3
votes
0answers
105 views

C# code for minimizing the sum of an array by dividing it's elements (repetition allowed) by 2 for k times

The assumption is that k is quite large as compared to no. of elements in the array and division by 2 returns ceiling of the result. Request for your review and suggestions for further improvements ...
3
votes
2answers
48 views

Best approach for converting list of nested dictionaries to a single dictionary with aggregate functions

I've looked through a lot of solutions on this topic, but I have been unable to adapt my case to a performant one. Suppose I have a list of dictionaries stored as: ...
4
votes
2answers
121 views

Increment values in a dictionary

In my continued venture to teach myself C# I came across an exercise using Dictionary. I created a class that has a method. In that method it creates a dictionary with keys/values. A string is ...
1
vote
0answers
30 views

Simplifying decision tree when working with map which has two keys and value as a slice

Can this logic not be simplified more, the code works, but it has become too much of a spaghetti. The requirements are that there should always be one connection if possible in ...
4
votes
1answer
41 views

Is this an optimal implementation for the knapsack algorithm?

I have implemented a solution for the knapsack problem while breaking an item is allowed. I've used the dictionary data structure where I used weight as a key and value per weight as a value. After ...
1
vote
1answer
51 views

Dictionary or custom Collection

I have a list of rule names coming from .xml file. These rule names needs to be validated against rule names in database (Validator.cs). If valid, then ...
1
vote
1answer
96 views

LeetCode: Divide Array in Sets of K Consecutive Numbers C#

https://leetcode.com/problems/divide-array-in-sets-of-k-consecutive-numbers/ Given an array of integers nums and a positive integer k, find whether it's possible to divide this array into sets of ...
1
vote
0answers
77 views

Convert dict to array in Python [closed]

I have a dictionary that looks like this: Counter({(1, 9): 3, (4, 2): 2, (3, 0): 1, (5, 4): 1}) I would like to convert it to an array that would look like this: ...
12
votes
3answers
1k views

Implementing a rectangle class

First I've to indicate that this is my homework. An example of a given input is: s1 = {'p1': (x1, y1), 'p2': (x2, y2)} where all names and coordinations are ...
7
votes
1answer
974 views

Merging two dictionaries together whilst adding keys but multiplying values

I have two dictionaries and a merged dictionary: dict1 = {-3: 0.3, -2: 0.1, 1: 0.8} dict2 = {0: 0.3, 1: 0.5, -1: 0.7} dict_merged = {} I have code that basically ...
2
votes
1answer
50 views

Iterating lists and updating dictionary for corresponding match logic improvement

I have two lists: Users - [<UserObject1>, <UserObject2>, ...] Contributions - [...
4
votes
2answers
194 views

Takes json input and builds dynamic json output based on values in input: Looking for a better way to accomplish this

I have this specific scenario where I'm going to get a JSON that could have multiple Objects. From the Multiple Objects I will create a new Json that can have nested arrays growing by n amount ...
1
vote
1answer
466 views

Premier League data scraper

I have started a project where I am scraping JSON-data from an API. How the scraping is done right now is done in a very repetitive way where the keys of interest are specified and scraped. The data-...
2
votes
0answers
60 views

Pythonic way to cast a dictionary into a pd.DataFrame with two columns?

I have a dictionary where for each key, a single value is stored. Say import pandas as pd dd = {'Alice': 40, 'Bob': 50, 'Charlie': 35} Now, I want to ...
10
votes
2answers
1k views

Better way to iterate through a dictionary and comparing its keys with itself

I have a dictionary with author names as keys and values of None. I want to use fuzzywuzzy ...
1
vote
0answers
86 views

get better performance [closed]

I have this code that works, but I'm sure that it can be done better, any suggestions? ...
-1
votes
1answer
48 views

Comparing dictionary values from list [closed]

I'm writing some Python code that will handle huge datasets. On a small scale, this snippet works fine, but as the datasets become bigger it grinds my script to a halt (I know it is this part as I ...
5
votes
1answer
55 views

Minimum amount of spaces inserted in a given string, such that it gets composed only of elements from a given list

The Challenge Given a big string and a list of smaller strings, find the minimum amount of spaces that must be inserted between characters of the string in such way that it becomes composed only of ...
2
votes
1answer
35 views

Print a word with numbers substituted for characters

I wrote the following Python program to take 1 word from the user and return certain characters replaced by numbers. Given a dictionary, the program should print all possible combinations of the same ...
1
vote
2answers
132 views

Bi Directional Dictionary

I wrote a class that extends the dict class to provide indexing like functionality, so I can find which key(s) map to a given value in the dict. It's pretty bare ...
0
votes
1answer
119 views

To convert all the class properties to IDictionary<string, dynamic>

I have the requirement to return the result of my ViewModel as a Dictionary of KeyValue pairs. My view model comprises of multiple classes and can have null values in properties. I need to return only ...
2
votes
1answer
69 views

Add items to Dictionary from another dictionary on cell value change

I have created a very simple Class Module and a Dictionary to store original values when the workbook is opened as part of this project ive been working on. When the workbook opens I call a test to ...
8
votes
3answers
732 views

Creating an affinity-matrix between protein and RNA sequences

I wrote an algorithm that analyzes protein-RNA interactions and I found that the following function is the bottleneck that causes performance issues: ...
5
votes
1answer
278 views

Normalizing mixed format nested dictionary with delimiter separated keys

I recently worked with some pickle files which had a really strange format where the keys are sometimes delimiter separated with colons and placed in the same depth but also mixed with ordinary key ...
1
vote
2answers
93 views

Check if dictionary keys are declared, if not leave them as true

I've tried with: dictionary.TryGetValue("MoreDetails", out bool MoreDetails); but if the key is not present it defaults to false, and I need it to default to ...
2
votes
1answer
69 views

Dictionary function for R

I'm new to R and have created a dictionary function. A user will input a phrase into a text field and the server will read it and see if there's a match in a back-end data table and if so, output the ...
12
votes
4answers
2k views

Extraction of value from a dict-tree, given a path of arbitrary length

Problem: We read a complex json-file which grants us a tree in terms of a python "dict of dicts". We're then requested to retrieve a specific path from the tree, represented by a list of elements. The ...
5
votes
2answers
556 views

Fantasy Game Inventory - Automate the Boring Stuff with Python

Below is my code for the Fantasy Game Inventory problem from Chapter 5 of Automate the Boring Stuff with Python. Is there anything I can do to make it cleaner or more efficient? The code starts out ...
3
votes
1answer
76 views

identifying pairwise groups from dictionary

I have a dictionary that looks like this ...
5
votes
3answers
584 views

Comparison of values in dictionary

I have the following dictionary: ...
3
votes
1answer
99 views

How do I efficiently create a dataframe from a list of dictionaries?

I used this API to download some data. The code is supposed to create a dataframe table using specific fields of an object, and it seems to work, but running slow. I think it would run faster if I ...
-1
votes
1answer
44 views

Dictionary comprehension with nested for loop and conditional if [closed]

Let's suppose I have two lists: list_b = ['cat.2','dog.6','bear.10','zebra.13'] list_a = ['cat','dog','bear','zebra'] I would like to create a dictionary with ...
4
votes
2answers
94 views

Mini-git class performance issue

I want to build Git class where i can store integers. FilesSet is where I store current state of integers. Commits' key is ...
3
votes
1answer
134 views

LeetCode: Time Based Key-Value Store C#

https://leetcode.com/problems/time-based-key-value-store/ Create a timebased key-value store class TimeMap, that supports two operations. ...
4
votes
1answer
72 views

Immutable Keyed Set

Description An immutable keyed set is a readonly collection of elements without duplicates or null values having each of the elements linked to exactly one key. Example This simple example ...
1
vote
2answers
1k views

Python, Iterate through a list sending batches of 100 records at a time to an API, then appending results to another list

I have a list of 9000 dictionaries and I am sending them to an API in batches of 100 (limit of the API). The API returns the list of 100 dictionaries just expanded with more key/value pairs. So both ...
4
votes
3answers
258 views

Bidirectional Map in C#

Inspired by this question and its answers, I've made my own version. ...
8
votes
5answers
2k views

Bidirectional Dictionary

The management of bidirectional mappings is a reoccuring topic. I took the time to write an (hopefully) efficient implementation. ...
5
votes
1answer
89 views

Automating a set a of weekly reports, including graphs and delivery of reports

I have been writing code to automate some weekly reports. I had help over on Stack Overflow. I have code that works for the most part, however there are a few things that I just can't seem to fix. In ...

1
2 3 4 5
8