Stack Exchange Network

Stack Exchange network consists of 175 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
The results are in! See what nearly 90,000 developers picked as their most loved, dreaded, and desired coding languages and more in the 2019 Developer Survey.

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.

13
votes
1answer
310 views

Persisted Dictionary Implementation

I'm using this code in an app that has hundreds of daily users. The code works, and passes all of the test cases I have. Occasionally some users report a problem that I don't get right to the bottom ...
2
votes
2answers
47 views

Fastest way to find dataframe indexes of column elements that exist as lists

I asked this question here: https://stackoverflow.com/q/55640147/5202255 and was told to post on this forum. I would like to know whether my solution can be improved or if there is another approach to ...
3
votes
1answer
92 views

Reverse dictionary where values are lists

I'm working on the following problem: I've got a dictionary like this one: dic={0:[0,1,2],1:[3,4,5]} And I want to reverse it so it looks like this: ...
2
votes
1answer
107 views

Sluggish Loop Transferring Dictionary Data to Spreadsheet

I've added a timer to my code and the bottleneck comes when I'm looping through 47 rows and inputting data from a dictionary that I previously loaded with values. Since i use these files for a lot of ...
12
votes
2answers
511 views

Count the occurrence of each unique word in the file

I've been doing a task for an interview that I will have soon. The requirement is to code the following problem in C#. Write a program (and prove that it works) that: Given a text file, count the ...
-2
votes
1answer
73 views

Eliminate shorter substrings from larger one

I have a dictionary that stores a string and its frequency which looks like this ...
0
votes
2answers
103 views

Counting sort in Swift

I have this sorting algorithm which takes an array of dictionary values: guard var imageUrlString = anyImage.value as? [String:AnyObject] else { return } I then ...
1
vote
3answers
139 views

Randomly pick key from dictionary weighted by the keys value

I was trying to write a function that would get a random card from a dictionary of cards in a players deck weighted by the number of cards of each type you have. I don't know if the solution I came up ...
6
votes
4answers
684 views

Parsing a string of key-value pairs as a dictionary

I always use nested list and dictionary comprehension for unstructured data and this is a common way I use it. ...
1
vote
2answers
30 views

Creating a dict with external and internal IP addresses provided a list of candidates

I created a function that finds internal and external IP addresses, returns them in dict with the keys external_ips and local_ips...
5
votes
5answers
9k 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
29 views

Appending values in Pandas column

I have a dictionary: x = {'[a]':'(1234)', '[b]':'(2345)', '[c]':'(xyzad)'} and a dataframe ...
9
votes
3answers
21k views

Get value from dictionary given a list of nested keys

I would like to get a deeply-nested value, for example {"a":{"b":{"c":"myValue"}} by providing the keys to traverse. I tried chaining together .get() but that didn'...
2
votes
1answer
11k 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? ...
1
vote
1answer
41 views

Transforming a dict of lists into a list of dicts

I would like to transform a dict of one format into a dict of another format. The raw_input dict will have the shape: ...
3
votes
5answers
520 views

Finding Isogram Word

An isogram (also known as a "nonpattern word") is a word or phrase without a repeating letter, however spaces and hyphens are allowed to appear multiple times. The ...
5
votes
3answers
1k 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++...
7
votes
3answers
364 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. ...
3
votes
3answers
213 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
64 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
2k 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
946 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
33 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
577 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
777 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
106 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 ...
5
votes
1answer
62 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
502 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
66 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
2answers
14k 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. ...
3
votes
1answer
54 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
276 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
69 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 ...
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 ...
5
votes
1answer
799 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: ...
7
votes
2answers
18k 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. ...
6
votes
1answer
169 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 ...
0
votes
1answer
86 views

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

I tried solving the Hash Tables: Ice Cream Parlor question in javascript: ...
7
votes
3answers
3k 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
15k views

Modifying nested dictionaries in Python

My task was to take a configuration specified as a dictionary and run some function with it (the actual function is not relevant here). After implementing that, I was asked to allow some "sweeping" of ...
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 ...
4
votes
1answer
935 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 ...
6
votes
4answers
5k views

Iterate over two collections of equal length

What's the best way to iterate over two collections of equal length? Currently I'm using this: ...
2
votes
2answers
3k 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: ...
0
votes
2answers
100 views

Building a graph using dictionary

I have an input text file which contains distance between 2 cities shown below ...
6
votes
0answers
218 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. ...
3
votes
3answers
455 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 ...
1
vote
2answers
65 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: ...
10
votes
3answers
52k views

Convert dict entries to sets and lists

Can you please tell me if there is a better way to do this? ...