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
6
votes
4answers
36k views

Adding to a dictionary and skipping duplicate keys

What is the cleanest way to use dictionaries and protect against an unhandled ArgumentException if the key already exists in the dictionary? I'd like to say that I ...
2
votes
2answers
535 views

Dictionary app using WIn32

I'm creating a dictionary app using Win32 API. I stored the word meaning in a file called dictionary.dic in the following format: Word Meaning A The first letter B The second ...
55
votes
2answers
3k views

Counting all the vowels in a passage of text

My son just started high school and in Math, he was asked to do some stats homework. The exercise was to count all the vowels in a passage of text, then answer some questions about frequency. Out of ...
3
votes
2answers
173 views

Functions to merge dictionaries with a comparison

I have several functions for merging some dictionaries but over time I created a more general function that would make all these others obsolete if it weren't slower. I have the specialized (and ...
2
votes
1answer
119 views

Optimize performance of flatten function in python

I have to flatten a large number (>300k) dicts to write them to a csv file. Example: ...
2
votes
2answers
2k views

Insert rows in the datagridview with a dictionary

I would like to improve the function below without calling twice InserisciRigaNote. Before I fill my dictionary. When I compare ...
5
votes
4answers
8k views

Recursively Save Python Dictionaries to HDF5 Files Using h5py

I have a bunch of custom classes for which I've implemented a method of saving files in HDF5 format using the h5py module. A bit of background: I've accomplished ...
2
votes
2answers
11k views

Most efficient dict filter on key tuple?

I have a dict wherein a value needs to be retrievable by any one of several keys. It seemed that making multiple dictionaries or multiple entries in a single ...
3
votes
3answers
4k views

Dynamic class instancing (with conditional parameters and methods) based on a dictionary

In an RPG game I'm developing, after building a base Weapon class, instead of having many subclasses of Weapon, I want the ...
2
votes
1answer
3k views

Writing a Counter object to a CSV-file in Python 3

In Python 3.4, a Counter object called cnt like this: ...
4
votes
2answers
724 views

Dictionary lookup of non-nullable struct into nullable destination

I've got an IDictionary<SomeT, DateTime> that does not always contain the desired key-value pair. For that reason, a target method expects a ...
4
votes
3answers
108 views

Efficient dictionary printing

Here's what my task is: Dependant on the "Logged In" user, they'll have different access rights and will see different menus. I have tried using the .get() ...
4
votes
3answers
124 views

Load recurring (but not strictly identical) sets of Key, Values into a DataFrame from text files

I am reading text files that contain data from observations. The format is not Fixed Width or Delimited, so I built a generator ...
4
votes
3answers
4k views

Custom Implementation of ObservableDictionary

I recently found myself in need of an IDictionary<TKey,TValue> implementation that was observable from a WPF UI. Since the .Net framework does not provide ...
7
votes
2answers
2k views

Copying a Dictionary and Replace its Values

I have a custom dictionary where the values are numpy arrays. I would like to have a convenience function that creates a copy of its content except that the values are changed. If no value is passed, ...
11
votes
1answer
519 views

iterating over the values of a list of ordered dictionaries

I am facing the following problem: I have a special data structure that is a dictionary whose keys are integers (dimensions). The values are also dictionaries whose keys are strings (geometric types) ...
6
votes
2answers
131 views

Unicode-capable symbol table (N-way search tree with hash buckets)

As in my previous question, this module is coupled with its own testing framework. As a symbol-table for a Unicode-capable programming language interpreter, I decided to combine the 3 types of ...
3
votes
2answers
235 views

Compare dicts and record changes

My goal is to continually update an object and record any changes and the times they were made at. The input has to be JSON but the output/storage format doesn't. This function will check a JSON ...
1
vote
1answer
6k views

Test if a key exists anywhere in a nested object

I have complex objects containing nested objects. I need to check if a key exists anywhere in the nested object. I wrote this code as a makeshift solution. Is there any other way to search for the key?...
1
vote
1answer
77 views

A Simple SortableDictionary for JavaScript

First, I must humbly admit that I've been a developer for many years but I've almost never had to work as a front-end, Web UI developer. I've been given an opportunity to work for an organization as ...
3
votes
2answers
619 views

Mapping a user input string to a corresponding block of code

My idea is I can define a block of code (inline) that corresponds to an input string then can call that block of code when given that input. I'm used to this sort ...
2
votes
1answer
2k views

Calculating sum of values in each child of dictionary for QTreeView

There is data stored in JSON file with the following structure: goods_data = {"year" : {"month" : {"day" : {"01" : {"name" : "some item", "price" : "10.01", "category" : "root | first | sub first | ...
8
votes
4answers
26k views

Dictionary GetValueOrDefault

I'm pretty sure there's no better way to do this but I thought a consensus on here might be nice. Let me know what you think. ...
7
votes
2answers
14k views

Wrapping tuples to be used as keys in a Dictionary

I'm currently working on a project where I have to map some objects to several properties. Basically I need a Dictionary with Tuples as keys and instances of MyClass as values. As using tuples can ...
1
vote
1answer
35 views

Reading XML files and finding pairs between the files

I read three files and parse a few individual fields from each row of the XML. Using these fields, I find the dictionaries that contain the same keys (ItemK and either SensorK for sensors or PointK ...
4
votes
2answers
531 views

Practice with dictionaries

Post a cursory read of this I implemented a simple dictionary and an interface to assign, replace, look up, and redefine its terms to apply the concepts. It's simple, but I'd still like to know any ...
4
votes
2answers
238 views

Wrapper class for adding elements to HashSet

I have many object of class Test. I want to be sure that among them, there are no two objects o1 and ...
2
votes
3answers
8k views

Grouping over a list of dictionaries

I am consuming data from an API that reads from a SharePoint list. The API is basically this: ...
5
votes
2answers
1k views

Counting words from standard input in Swift

I know Swift isn't exactly meant to be used to write your classic stdin to stdout scripts, and that Python, Ruby, Perl, bash, awk, and friends are much better in this area, but I'd still like to see ...
1
vote
1answer
129 views

Map all symbols in module to dictionary

The div and add functions are located randomly in my package structure. I have a function with this signature: ...
0
votes
1answer
295 views

Data Structures C# Dictionary<int,user> and user has a property that is a list<numbers>

I am about to post a question to Stack Overflow about how to do a better job adding a number to the list inside the User class. But I feel if I refactored this I ...
3
votes
2answers
168 views

Iterate over large amount of words in Python

I wrote a program that should check a dictionary that contains about 50000 other dictionaries. In those dictionaries, one of the keys has a list of words as value. Now, I iterate over those words, ...
2
votes
3answers
144 views

Search dictionary by value

I have a dictionary which I use to lookup my binary and ASCII values (from A - P). It works, but my ascii2bin function just doesn't really feel right (and beautiful)...
11
votes
1answer
426 views

OOP paradigm implementation of a Dictionary data model

Here is the implementation of interface Dictionary using chained hash table class HashTableChained. Despite item 22* saying ...
6
votes
2answers
291 views

InfixDictionary: Data structure for Infix string lookup

I needed a data structure to quickly find all previously inserted values, that have the given string as key or substring (full text search). At first, I tried out some tree structures (infix trie/...
5
votes
5answers
11k views

DuplicateDictionary - A dictionary-like class which allows duplicates

Since I couldn't find any good answers I made my own class called DuplicateDictionary for personal usage. I would like some tips to improve it. ...
3
votes
1answer
98 views

CSV parsing program that creates distinct header rows with transaction rows underneath

My code reads in the data using DictReader, then creates a header row that contains my composite key (PEOPLE_ID, DON_DATE), and then adds various values that are ...
4
votes
2answers
943 views

Commission calculation

I am trying to improve the performance of the current solution for calculating commission in a betting platform. The following is the code currently used to solve the problem. The primary problem ...
2
votes
1answer
13k views

Unique dictionary values - print keys

I'm working on this code for exam in an MIT Python course. It's working but I'm trying to improve it. What could I do, and what should I avoid? ...
7
votes
4answers
1k views

Fast evaluation of Euclidean distance with sparse data

I am working on a KNN implementation for sparse datasets (that I apply to text analysis). My points are represented by a Dictionary<string, double>, each key ...
5
votes
3answers
10k views

Return IEnumerable<KeyValuePair> from a private method; use Dictionary or anon. type?

Is it okay to return IEnumerable<KeyValuePair<string, string>> from a private method instead of returning a read-only dictionary? This allows for ...
1
vote
1answer
291 views

Dictionary file manager

The dictionary class loads entries from a file and then can perform operations on them. The dictionary class then stores the entries back into the file. I would like to know the best way to check if ...
7
votes
1answer
16k views

Updating a .csv file

I have a CSV file, call it csv_file. It has the following content: Username, Password name1, pass1 name2, pass2 ... I also have a dictionary, call it ...
2
votes
1answer
2k views

Python lazy dictionary

Here is a lazy dictionary with test cases. ...
7
votes
1answer
1k views

Python DefaultDict implementation in JavaScript

I found Python's defaultdict and OrderedDict incredibly useful, hence I attempted an implementation in JavaScript. As JavaScript ...
4
votes
2answers
256 views

Fetch plist file

I have a plist file with many nested dictionaries inside of it, and I wanna fetch them all to my code. Isn't there any more efficient way to do that than nested for-loops? ...
8
votes
1answer
2k views

Dictionary (with silly hash)

Based on this question (but fixed so it can run). I have kept the code as close to the original as possible. I have Marked all the changes with Loki (should be easy to spot). Code here is written in ...
5
votes
1answer
282 views

Python DictionaryTagger class takes too long to initialize

With big inspiration from code from different webpages, I have created this DictionaryTagger. My problem is that it takes around 2 sec. to initialize the taggers / ...
2
votes
1answer
87 views

Print dict with varying-length lists

Is there a shorter way of taking a dict with varying length lists and printing it to screen? Shortcomings of this method also include that values which aren't lists are printed as letters separated by ...
2
votes
1answer
177 views

Iterate over items in a set of dicts

I'm using the following code to initialise 8 I/O-ports (i.e. GPIO pins on a Raspberry Pi). That's 4 x 2 pins, each duo controls a switch, A to D, and each duo consists of a pin for On and a pin for ...