Stack Exchange Network

Stack Exchange network consists of 174 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange

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.

3
votes
3answers
201 views

Word frequencies from large body of scraped text

I have a file with word frequency logs from a very messy corpus of scraped Polish text that I am trying to clean to get accurate word frequencies. Since this is a big text file, I divided it into ...
1
vote
2answers
60 views

Pythonic way of checking for dict keys

When checking a python dict for a key, which is the better way here: (I can't figure how to use dict.get() to make this cleaner) ...
7
votes
2answers
748 views

Merge two list of dicts with same key

I have two lists of dictionaries. Both lists always have the same ids. I want to get the following result: ...
4
votes
2answers
122 views

C++ Implementation of a dictionary data structure

I am quite new to C++ and would like some feedback on my implementation of a dictionary data structure. The code is below. ...
0
votes
1answer
31 views

Swift append an array when it's been declared as Any

I'm learning Swift and I have a following problem: I create a dictionary containing some data, one of which is stored as an array. I want make an operation on this array to add some info. Currently I ...
3
votes
2answers
152 views

Word ladders program in Python

Background information: Given two different strings of equal length, the spacing between them is the number of other strings you would need to connect them on a word ladder. Alternately, this is 1 ...
7
votes
2answers
490 views

Generic Dictionary Equality Comparer

I created the below comparer to allow me to use a generic dictionary as a key to another generic dictionary. My GetHashCode implementation creates a hash based on ...
-2
votes
1answer
77 views

Method to populate a dictionary from properties

I have a class with some properties. In the class I have a method that is "collecting" all the properties in a specific instance of the class to a dictionary, with the properties name being the ...
4
votes
1answer
57 views

Preparing tabular data to be sent as json

I query a database and pass the data for processing as a DataTable. After all computations (grouping, filtering, formatting etc.) I need to send it to a Web-Service ...
3
votes
2answers
437 views

Search in a nested list of a dictionary

I have a dictionary structured as {a_1: [((b_11,c_11),d_11), ((b_12, c_12), d_12), ...], a_2: [...], ...}. I want to extract the maximum abs(c) among all the ...
1
vote
1answer
56 views

Search dictionary for matching values

I have a dictionary self.indexList = {} filled with 3-item-lists values = [lineId, nominalLineId, vertex] for each dictionary ...
3
votes
1answer
48 views

turn a dict that may contain a pandas dataframe to several dicts

I have a dict that may be 'infinitely' nested and contain several pandas DataFrame's (all the DataFrame's have the same amount of rows). I want to create a new dict for each row in the DataFrame's, ...
1
vote
0answers
253 views

Filling values for nested dictionaries

I have a text file where any name followed with sequence word is considered a dictionary. The task is to go through the keys and values of a particular dictionary, which is already identified, and see ...
0
votes
1answer
66 views

Dictionary to generate control names

I have found myself referencing controls on a form (think Windows forms but more proprietary) by hard-typing their names in over and over again. Often I'll have a number of similar controls which ...
0
votes
1answer
60 views

Hash Tables: Ice Cream Parlor solution in javascript [closed]

I tried solving the Hash Tables: Ice Cream Parlor question in javascript: ...
12
votes
3answers
3k views

Codewars: Reduce strings to one character

I am trying to solve a puzzle in a performant way. This is the puzzle. Simply explained: you have a String and you must reduce it to one character with the given rules. This is the solution to the ...
5
votes
1answer
432 views

Asynchronous dictionary in Python

So I am working on writing a discord bot with discord.py. I decided, rather than making a serie of if/elif, to map the messages to the functions in a dictionnary, like so: ...
4
votes
1answer
702 views

Hackerrank Day 8: Dictionaries and Maps solution in C++

This is a solution for the Day 8 hackerrank.com challenge. The basic idea of the challenge is to create a mapping of names to phone numbers based on the the given input, and later look up the phone ...
2
votes
2answers
2k views

Accessing a subset of keys from a nested dictionary in Python

I am trying to access data from Coinmarketcap API in Python and came up with the following code: ...
6
votes
0answers
144 views

IndexedArray Class: Uses a Dictionary Keys to Index a 2 Dimensional Array of Values

This class encapsulates a 2D Array and a Scripting Dictionary. Values are add or returned from to the Array using a Key and a ColumnIndex, e.g. ...
0
votes
2answers
94 views

Building a graph using dictionary

I have an input text file which contains distance between 2 cities shown below ...
1
vote
2answers
63 views

Reclassifying movies by theme

Any efficient way to solve the following problem assuming data is large. I solved the problem but how can I improve the code, which will make it efficient. any suggestions? Data: ...
7
votes
3answers
237 views

Scraping Clinical Studies database (via ClinicalTrials.Gov)

I have written the following script to scrape data from the U.S. National Library of Medicine website ClinicalTrials.Gov based on an NCTID. ...
6
votes
0answers
83 views

Agent-based Immutable Map

I am in the process of removing the last few pieces of mutable state from an F#-based distributed system. Some of the remaining mutable state is a ...
1
vote
2answers
115 views

Substitute IDs to word tokens

I writing a function in Python to substitute word tokens in a sentence with IDs. The sentence is a list of tokens (list_of_tokens). The IDs are provided in a dictionary mapping tokens with an IDs (...
3
votes
1answer
26 views

Consume rest endpoint removing payload's unwanted properties and falsy values

Let's suppose that there's a third part web service and I want to make a GET request to it and use the response to feed my project's service. Next code will allow me to create a dict object only with ...
4
votes
1answer
172 views

Complete ObservableDictionary

In conjunction with a recent question of mine, I found that an ObservableDictionary would be very handy for my situation, so I decided to implement one. I've ...
4
votes
0answers
58 views

General Purpose C Dictionary

I'm trying to create a general purpose C dictionary (as an opaque data type) capable of dynamically allocating basic types (ints, floats, strings and longs) as well as accepting void pointers to ...
7
votes
3answers
2k views

Two Sum Leetcode

Looking for some feedback on the Two Sum LeetCode problem. Looking for feedback on code style in general, use of var, variable naming and initialization, return placement, and any other feedback or ...
3
votes
1answer
264 views

C# basic dictionary (hash) implementation

I have implemented a very basic hash data structure with basic set/retrieve methods. A good example of use of this implementation would be a phone-book. I have used as underneath storage structure an ...
9
votes
1answer
1k views

Product of dictionary values

Elements that smell funny: argument unpacking to itertools.product. I'm needing sorted keys (even though I don't care about key order in the final result). ...
6
votes
1answer
163 views

Dictrie: Extending the Python dictionary into a Trie

I implemented a trie in Python2.7 as a dictionary of dictionaries by extending the UserDict class to allow native dictionary access syntax and iteration. For example, ...
3
votes
2answers
94 views

V2. Interactive dictionary with inexact look ups (updated)

Recently I published a post in which three people made pretty good suggestions. I've learnt a lot since then thanks to them! From among many things, they encouraged me to use classes. And that's ...
9
votes
5answers
277 views

Applying a string-identified effect on an image

Task: Given an image object and an effect identifier (string), apply the effect identified by the string on the image. The library of effects can grow as the program grows. Code 1: ...
10
votes
2answers
2k views

Invert a dictionary to a dictionary of lists

I have a dictionary whose keys are related to list of values, but any value may be related to many keys, hence be contained in various lists-attached-keys. To highlight such relation; I build (in ...
1
vote
0answers
54 views

A fast integer key map in Java via a van Emde Boas tree

Introduction The following data structure is a dictionary mapping primitive int values to any value type. Basically, under the hood it is a hash table, where a ...
5
votes
3answers
782 views

Inserting and fetching values slower on an unordered_map in C++ than on a dictionary in Python

I was solving a CodeForces problem, and kept getting Time Limit Exceeded, so as usual in these cases, I decided to try to migrate my code from Python to C++ in order to go faster. I noticed that my C++...
3
votes
3answers
475 views

Associating a name with each bit in a bitmask

I have the following code: ...
4
votes
1answer
313 views

Equivalent of Python's dict.update for STL maps in C++

dict objects in Python have an update method that can be used to extend one dictionary with all items from another, possibly ...
0
votes
1answer
33 views

how to filter text from a string and convert it to dictionary and check for matching values in python

I am new to this community, I have tried this below code, this works fine, but looking for a better way of approaching for performance. Please edit my question, it it is not understandable. I have a ...
5
votes
1answer
787 views

Plotting text from a dictionary with Matplotlib

I have the following dictionary: ...
0
votes
1answer
241 views

Dictionary iteration with many loops

I have a dictionary iteration that uses a for-each comparisment in order to find multiple equalities in a string (fileline). ...
3
votes
2answers
4k views

Sort dictionary by increasing length of its values

Given a dictionary where the values are iterables, print the dictionary sorted by the length of its values. ...
1
vote
0answers
44 views

Calculating the number of matches for a tuple, a pair of nodes and a mapping

For a current node_pair, this program computes the number of variables matches it has. The matches for a node pair combined with a key are stored in a weight_dictionary with keys for each node pair. ...
5
votes
1answer
1k views

Ranking players in a league by sorting the contents of an OrderedDict

I'm new to python. I'm having second thoughts on my approach to this problem: The LeagueTable class tracks the score of each player in a league. After each game, the player records their score ...
11
votes
3answers
3k views

Removing entries from a dictionary containing bad words

I have a dictionary with each item containing a quote in another dictionary: ...
2
votes
2answers
115 views

PainlessDictionary for painless debugging

While working with dictionaries I've been always running into the same two problems (who wasn't?): The indexer throws the KeyNotFoundExcepion if you try to ...
2
votes
1answer
524 views

Update dictionary in constant time in Python

Consider a large list of 4 character strings. For example: ['P0BH', 'LF3J', 'MA1Y', 'STSM', '8Y74', 'JWBD'] I want to add a new string in the following precise manner: If the new string already ...
6
votes
1answer
215 views

Finding added keys, removed keys, and unchanged keys in ordereddict

I'm comparing two OrderedDict objects and I need to find added keys, removed keys, and keys that are present in both (the intersection). Sets are designed for ...
5
votes
1answer
102 views

Collating list of dicts to table format

I've got a list of dicts, data, that updates periodically and is persisted to a database. Every time data is updated, the gui ...