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
0
votes
1answer
82 views

Produce all multiples of a set of primes up to a certain limit

I have some Python code that generates all possible multiples and combinations of a given set of primes up to a certain limit. The code runs and does exactly what I intend it to do, now I am trying to ...
5
votes
2answers
10k views

Adding labels and fields to a nested JSON

I have a dataframe: ...
3
votes
1answer
2k views

Storing and retrieving student scores in three subjects

This is written to find percentages of three subjects. Original HackerRank practice problem is here. Input Format The first line contains the integer N, the number of students. The next N ...
8
votes
1answer
2k views

Extending CGPoint to conform to Hashable

For Advent of Code Day 1, I found myself needing to use a tuple as a key in a dictionary. Seeing that I can't extend tuples in Swift, I decided to extend CGPoint ...
8
votes
3answers
825 views

Word Pattern challenge in LeetCode

I solved this problem from LeetCode: Given a pattern and a string str, find if str follows the same pattern. Here follow means a full match, such that there is a bijection between a letter ...
4
votes
1answer
338 views

Phonetic Alphabet Trainer

This is a little program I put together to help people learn the phonetic alphabet. Feel free to query the code. ...
5
votes
0answers
66 views

Elegant way to alter datasets with explicit filters

I would like to write a small helper to filter datasets. Each dataset is a dictionary and some filters I want to apply are common to all the datasets. That my needs, I wrote this following pattern: <...
3
votes
2answers
514 views

ConcurrentDictionary, Store Key and Compression

So i have a ConcurrentDictionary<int, string> The "int" is merely the way i store the key, which i want more recommendations on. Currently i do like this. ...
7
votes
1answer
659 views

Constant keys thread safe dictionary

I find that I use this pattern a lot where I have a dictionary which I would only read from and update and wouldn't add/remove keys. In that case, using ...
1
vote
2answers
3k views

Finding the closest value and matching it with the correct item in the list

I have list values with their IDs like this: ID Value A 1.2 B 4.2 C 7.2 D 10.2 In C#, I want to find the ID with the closest value to a given value ...
5
votes
0answers
1k views

Decode HTML Entities in VBA using regex and dictionary

I receive HTML-encoded text that includes named and numbered entities, and I need the decoded HTML. There were just too many bad solutions for this online. I use regex pattern ...
2
votes
3answers
464 views

Simplify definition of a dictionary with default return value

I need a constant (dictionary with values and default return value if there are no defined value for a key). Searching for any ways to simplify the code. Without a default value I can simply define a ...
2
votes
1answer
102 views

Dictionary Parser Class

I'm working on a parser library for substituting strings in dictionaries, with things like globals etc. Wanting to get opinions on the direction I'm taking and where I can improve the script. This ...
1
vote
2answers
128 views

Generation of Dictionary in Python

Is there a way to refactor the following Python code so that the number of lines in generation of the dictionary can be reduced? ...
3
votes
2answers
708 views

Dictionary populated on demand

I work with an embedded target that contains a list of commands and registers that may change from one device to another. So I need to build my commands list from metadata received from that ...
10
votes
1answer
147 views

Using generators to print the tree-like structure of a project

The goal of this code is to print the entity tree of a VHDL project. There are a readme and very minimal tests on the github repo. I am trying to refactor the code to use generators in order to ...
5
votes
2answers
530 views

Python Cartesian Product in a constrained dictonary

I want to calculate the Cartesian product of n copies of a small list, marker=[0,1,2]. I want to use these Cartesian product ...
1
vote
1answer
553 views

VBA performance with Early Bind vs. Late Bind on called Sub-procedure

I was using early bind to reference the dictionary and realised that some users might not be willing to manually add the reference to use it and just consider the macro to be 'broken'. I looked at ...
4
votes
2answers
1k views

A 'flexible' VBA approach to lookups using arrays, scripting dictionary and user input

In my previous post Optimise compare and match method using scripting.dictionary in VBA I wanted to address optimising the scripting.dictionary approach I was using and I feel I have achieved that (...
2
votes
1answer
3k views

Optimise compare and match method using scripting.dictionary in VBA

In my previous post I was looking for a better solution to write a single column of a 2D array into a worksheet besides looping between code and worksheet and finally managed to achieve that. On ...
4
votes
1answer
3k views

GetHashCode of a Dictionary

There is a huge documentation about using and generating hashcodes for objects that will go into a dictionary, really few more if you try to look about hashcode of a dictionary. No, the default ...
0
votes
2answers
4k views

Searching a dictionary

After some advice, which method do you think is better to use when searching a dictionary for the matching value(s)? Method One ...
3
votes
1answer
392 views

Load txt to Scripting.Dictionary

This code load a 40MB txt into a dictionary. It runs in about 40 seconds (sometimes 20, no idea why). Is there a way to make it run under 4 seconds, or hopefully in 1 second? ...
4
votes
1answer
172 views

Comparing two lists under 6 columns with 32000 rows in Excel

I need to import 2 .s19 files to Excel and then compare across 6 Columns and store the output to a txt file. I have my data from column A to F. My current program doesn't store the data using a ...
6
votes
1answer
180 views

Container (dict preserving key order, with attribute access)

This class is part of the Construct library. Container is a dict that: turns attribute access into key access so ...
2
votes
1answer
1k views

IEnumerable to typed Dictionary

Scenario A portable controls/widgets library for Xamarin.Forms (PCL Profile 111) contains a combobox/dropdown/picker control where the ItemsSource property is an <...
2
votes
1answer
3k views

Nth Fibonacci number (Bottom-up with dict)

This is an algorithm that I wrote to get the nth Fibonacci number using bottom-up dictionary. How can I make this better/more efficient? ...
2
votes
1answer
1k views

Normalisation of a dict of dicts

...
2
votes
0answers
46 views

List of lists from file

I'm writing a sub-routine in AppleScript to get text from a file and insert that text in a list of lists forming a dictionary. Text File: a:b c:d e:f Expected ...
5
votes
1answer
382 views

Generate dictionary of points on n-sphere

This is a long-shot, but my question is to simply optimize this particular function in some code I have written: ...
8
votes
3answers
2k views

Word-counting script in C#

My goal is to read from standard input, break up the input into words (Unicode letters and apostrophes), case-insensitively, and produce a report to standard output, where each line is a word followed ...
7
votes
2answers
836 views

Looking for primes with all-different digits

I recently answered a question on Mathematics Stack Exchange, where I used a small Python program to check the following : For all 6-digit numbers, with all digits being different, choosing the ...
4
votes
1answer
1k views

Using a LinkedList type of adjacency list to create the word game: WordLadder

The user puts in a starting word and an ending word. My code creates a ladder between these words of words that are different by one letter. Start: gain End: fire Output: ...
3
votes
2answers
18k views

TypeScript Dictionary class

I recently implemented a dictionary class in TypeScript. I'm still new to JavaScript so I'm curious what people think about it. ...
2
votes
2answers
745 views

Concurrent bidirectional dictionary

I've been agonizing over this for an hour or two. I require a bidirectional dictionary that was thread safe. From what I understand about dictionaries, they're thread safe when being read from, but no ...
5
votes
1answer
182 views

AutoDictionary for objects with a key property

The normal dictiory separates the key from the value... but what if the key is a part of the item it stores? It then forces you to enter the same things twice, once for the key and agian for the item. ...
4
votes
2answers
696 views

Python lazy dict with iterator in constructor

This question began as an off-topic answer to this question, but the code here serves a different goal. I wrote the following class for the purpose of populating a dict on demand from an iterator. ...
2
votes
1answer
7k views

Flatten a nested dict structure in Python

For some post-processing, I need to flatten a structure like this ...
5
votes
2answers
1k views

Dictionary as context manager

I've created a class that implements customized addition, subtraction, etc. But for this class I'd like to have some additional parameters for these methods (__add__...
1
vote
0answers
83 views

Implement “at” lens for Data.Map

I've been working on adding an operation like Data.Lens.At.at to Data.Map. This uses an extremely fast, extremely small, and ...
9
votes
10answers
2k views

Writing an anagram efficiently

I know this question has been asked before now but in Python. Recently, I set out to write an anagram in C#. For instance, orchestra can be rearranged into carthorse and the anagram should not have ...
4
votes
2answers
1k views

Idiomatic word counting in Rust

My goal is to read from standard input, break up the input into words, case-insensitively, and produce a report to standard output, where each line is a word followed by a space followed by its count. ...
8
votes
2answers
22k views

Extracting values from dictionaries where the keys match

I have two Dictionaries with around 65,000 KeyValuePairs each. I used foreach and if-else statements to compare them and get values, but it goes very slow. How could I optimize my code and gain more ...
2
votes
1answer
1k views

Clustering similar tweets in a corpus

I am attempting to write a statistical program using an LDA model I've trained/created using Gensim. I am very new to Python and am a student level programmer. This current program is working and ...
2
votes
2answers
967 views

Take a result set and organize it into a dictionary

I'm trying to take a result set and organize it into a dictionary then assign the dictionary values to variables that are publicly accessible from my controller. My issue is I have to check if there ...
1
vote
2answers
438 views

Permute and count between nested dictionaries

Goal: Permute inner values between two dictionaries with matching outer key, Save permuatations in counter, Move to next outer key, update counter with new permutations. Problem: Many lookups on ...
1
vote
2answers
532 views

Matching lines in a CSV file with items in a dictionary

I was wondering if there was a better way of writing this... I have a CSV file (about 6640 lines). After reading through the file, the values for the DFN_Network ...
1
vote
1answer
173 views

A basic pure Python hash map using a tree

I would like feedback on my first attempt to understand how hash tables work. I've read some on how hash tables use modulo operations to find the location of a key. Can you help me understand, ...
0
votes
1answer
2k views

Match two dictionary keys efficiently in Python

I have two dictionaries that I need the keys to match and if they match i will get the value of the first dictionary and then get the value of 2nd dictionary and build a new dictionary out of those. ...
3
votes
3answers
7k views

Search in a big dictionary Python

I have a big Python dictionary with more then 150,000 keys every key has list value. This dictionary contains infinitive words as key and all grammatical forms of these words as values: ...