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
2
votes
1answer
656 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
223 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
147 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 ...
4
votes
1answer
12k views

Removing key/value pairs in list of dicts

I have a list of dicts that all have the same keys. If a key's value is None in all dicts then I want to remove them (A solution that creates a new dict is fine as ...
5
votes
2answers
2k views

Create URL query string from dictionary

I have a dictionary of parameters and value, and the function creates a URL query string from it: ...
0
votes
2answers
10k views

Invoking functions using a function pointer approach [closed]

I re-used this answer from this StackOverflow answer to simulate a function pointer approach available in high-level languages like C. While using this approach in Python, the dictionary I am ...
2
votes
1answer
121 views

Aggregate loans report without using Python standard aggregate or group functions

I've written the following as a code assignment (Python 2.7). The task is to aggregate the loans csv file from the accounts department by (Network, Product, Month) with the total currency amounts, and ...
3
votes
4answers
9k views

Sorting dictionary alphabetically

I have this method which successfully sorts the incoming dictionary alphabetically: ...
6
votes
2answers
9k views

Pythonic way to flatten nested dictionarys

Here's my attempt to write a function that flattens a nested dictionary structure in Python 3.6 This came about because I had a nested dictionary structure of data I wanted to visualize in the ...
6
votes
1answer
1k views

Implementing a dictionary and thesaurus in Python

Write code that functions as both a dictionary and a thesaurus. Supported operations: Add a word and its definition to the dictionary Add a synonym to a word in the dictionary Look up ...
2
votes
1answer
659 views

Ansible playbook to generate webserver folder structure with users and projects

I try to generate with ansible a folder structure for a webserver with users and linked projects. The playbook works. But with more users and projects it gets quite complex to handle. How can I ...
7
votes
2answers
9k views

List all possible permutations from a python dictionary of lists

The following code takes a dictionary of lists (indexed by keyword) and converts it into a list of list of dictionaries that contains all possible permutations of those lists. However, my solution ...
3
votes
2answers
287 views

HomogeneousDict - The Python dictionary that can have homogeneous keys

I've created a subclass of Python's builtin dictionary dict. The subclass allows dictionaries to have multiple keys with the same value. Hence the name "homogeneous"...
7
votes
1answer
293 views

Project Euler 22: Names scores using dictionary

I solved Project Euler 22 using Python 3. The problem reads as follows: Using names.txt (right click and 'Save Link/Target As...'), a 46K text file containing over five-thousand first names, ...
9
votes
3answers
3k views

Dictionary of dictionary - Get 2nd keys

I have a dictionary of dictionary such as d below, and I would like to get the list of all keys but not on the first level (i.e. ...
5
votes
1answer
4k views

Calculate probability of word occurence

I am pretty new in Python and I am not sure if I did everything right in my program. May someone to check it, please. Thank you! First of all, I have a text file, for example, ...
5
votes
3answers
285 views

CSV parser for a tech test

The requirements: The following was an interview test for a junior position. You’ve been asked to write a program that will take a dictionary file (csv list of words) and output the number of ...
3
votes
2answers
466 views

Filtering out entries in a database search result that have an error

Note: I based my solution on this SO question I have this list of dictionaries. ...
12
votes
3answers
516 views

Key Order Agnostic, 2D Dictionary

Note: I am using Unity3D game engine, which uses .Net 2.0 (.Net 2.0.50727.1433 to be precise) to compile code, so I don't have access to newest features of C# 6, or even C# 5. Please keep this in ...
4
votes
2answers
4k views

DataTable runtime grouping on user defined criteria

I one of my tools I use the user can define grouping for a DataTable. The criteria are known only at run-time. To achieve this I use a ...
3
votes
2answers
836 views

Parsing very simple CSS into selector and declarations (as as single piece)

The last part of my HTML genrator requries a few styles. Because all styles are inline and the styling is for emails there won't be any fancy selectors, just by element, id or class. The most ...
4
votes
1answer
2k views

Textual Dictionary Program

I am a beginner in programming and I have written a little program that manages a list of words or strings to examine my understanding of Java and object oriented programming. I am interested in your ...
8
votes
2answers
1k views

Brick Wall Leetcode challenge

I solved this problem on Leetcode There is a brick wall in front of you. The wall is rectangular and has several rows of bricks. The bricks have the same height but different width. You want to ...
5
votes
1answer
7k views

Python 3 - Get n greatest elements in dictionary

Given an dictionary with lists as values this piece of code is dedicated to find the n keys with the longest lists as values. It works, but there has to be a more elegant solution. ...
4
votes
1answer
78 views

Python class hierarchy, extend ancestor data

I have a hierarchy of entities that should contain dictionaries with metadata. Any sub-class should inherit its ancestor dictionary and be able to add some key-values (delete inherit keys is not ...
6
votes
2answers
133 views

Dictionary of key signatures for various major and minor scales

I've been working on a simple program that matches a scale with its key signature. It's fairly simple, but I feel there is redundancy in the dict I created since I don't know how I could assign two ...
8
votes
1answer
18k views

Adjacency List Graph representation on python

I began to have my Graph Theory classes on university, and when it comes to representation, the adjacency matrix and adjacency list are the ones that we need to use for our homework and such. At the ...
2
votes
1answer
1k views

Shift a python dictionnary values

I wrote this function today that shift the values of a dictionnary: ...
3
votes
1answer
111 views

Compact Braille lookup

A related question got me thinking about a compact Braille dictionary. It certainly would be easier with Int16 or string but was going for most compact. I don't think there is a case insensitive char ...
3
votes
2answers
6k views

Mapping .csv rows to a Dictionary

I have a .csv file in which each row represents an association between a software application and a web server. My goal is to fetch a List<Server> by ...
1
vote
1answer
616 views

Counting and scoring two- and three-word phrases

I am writing a function to take a list of words and score 2 and 3 word phrases based on occurrence while removing any phrase occurrences with a score of less than 3. As someone kinda new to python, i'...
1
vote
1answer
480 views

Read JSON as a dictionary of country codes and names

For a small system I need the Country Code mapped to the country name (e.g. "GB"-> "United Kingdom"). To accomplish that I read a JSON file and save it to a dictionary using swiftyJSON. Is there a ...
5
votes
1answer
259 views

Python function to generate Spanish conjugations

I tried to make a Python function to generate present tense Spanish conjugations. ...
12
votes
3answers
7k views

Creating zip but for dictionaries

I found myself needed zip but for dictionaries, and wanted to know if there is any way I can make this shorter and more concise, and/or faster. Also I cannot figure out what the type hinting might be ...
1
vote
0answers
54 views

Generate user form fields based on a dictionary that may have nested dictionaries

This piece of code is doing what I need it to do but I'm still not happy with it. Here's the main logic to it: Iterating over a dictionary, I want to treat differently the one item that has the key '...
2
votes
1answer
51 views

One method for changing one of the properties

I have a few resources set in my class – coins, diamonds, hearts, enum of these resources names, and method for increasing specified resource. I want to make single "Increase" method for all resources ...
5
votes
2answers
240 views

A python default dictionary which seamlessly saves to disk

I sometimes do experiments at work and separate the computation and the analysis so I can do the computation on a cluster and the analysis locally and sometimes in a Jupyter notebook. I wrote a class ...
8
votes
3answers
3k views

Create dictionary with default immutable keys

I've created a dictionary subclass with a set of default immutable keys. ...
10
votes
2answers
766 views

Finding roughly matching genome sequences in Python dictionary

The purpose of my code here is to play a part in genome sequencing analysis, and while functional it takes days to run, so I am looking for any way I can improve speed. The input is up to 500 million ...
13
votes
4answers
32k 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'...
11
votes
1answer
1k views

Enumerable Custom Collections in VBA with Dictionary features like Exists

To Collect or Hash The VBA.Collection has a number of limitations, but it is enumerable and you can refer to items by index or key. But the VBA implementation of a ...
6
votes
0answers
365 views

Van Emde Boas tree -based map in Java [duplicate]

(Follow-up question: Improved Van Emde Boas tree based map in Java) For the experimental part of my MSc thesis I was working on van Emde Boas tree, and I have this: ...
2
votes
1answer
376 views

Dictionary with ISet key as a collection of names

I'm writing a command-line utility and I need to find commands (and parameters) by name. The name can either be a full name like save or a shortcut ...
1
vote
2answers
61 views

Printing a pattern through the use of a dictionary

We had to port a c program to python. The code works but uses a dictionary to solve the problem. This doesn't feel like the right use of a dictionary. Is there a better way? ...
5
votes
2answers
611 views

Matching two lists of dicts, strictly and more loosely

Two lists of dictionaries. Dicts in A and B can be matched by a particular dict key that may be identical or similar. The result should be a list of the source key from A, the matching key from B, and ...
4
votes
2answers
104 views

Sorting a numbered table of contents and the contents associated with it

Given a numbered table of contents with headers and the content of each section, I wanted to sort them correctly according to only the numeric value. The first challenge: section numbers can be ...
2
votes
3answers
3k views

Methods to create C# dictionaries, with static keys/values, in fluent notation

I created these little utility methods to build fluent C# dictionaries. The value declarations shall be quick to write and easy to comprehend when somebody views the code. Usage conditions are as ...
2
votes
1answer
555 views

Ordered Map in C++

This is the final version of my ordered-by-insertion map in C++. What do you think and how can I make it even better? I'm open to all kind of suggestions! I intend to make a similar class, this time, ...
1
vote
0answers
2k views

Ordered-by-insertion map

The main problem that I tried to tackle here was trying not to have the erase method to be \$O(n)\$. I kept two data structures: a linked-list of pairs and a map of a key and a pair containing a value ...
1
vote
2answers
266 views

Count Characters Function PHP

As part of studying algorithms, I needed to make a function to count occurrences of characters in a string. My solution is below. I'd like some feedback about how I did - could the implementation be ...