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.

learn more… | top users | synonyms

-1
votes
0answers
24 views

Json file, dictionary [on hold]

I have some json file and its rows are dictionary. I already use ast package and coded next program: ...
7
votes
2answers
341 views

Dictionary of attributes and values

In the code below, I have a dictionary of attributes and values. I am checking to see if the value if an attribute is True, and if so adding the attribute to a list for later processing (it becomes ...
0
votes
1answer
44 views

Performance issue with conditionally removing keys from a dictionary [closed]

I'm new to Python (2.7 Spyder). My code takes a long time to execute, and seems overly complicated. I'd like to use the range function but it isn't behaving as expected so, I'm using a comparison of ...
1
vote
1answer
43 views

Convert 2D list to dict of list of index

I have a 2D list like this: ...
5
votes
4answers
117 views

Passing parameters to a query

I have a function that takes a Dictionary<String, Object> as an argument. It uses this Dictionary to create parameters ...
2
votes
2answers
77 views

Error Handling When Using Dictionary

I have set up a Dictionary that calls on a class to fill a DataGridView via SQL statements. The problem is in two (out of 5) ...
5
votes
1answer
71 views

Spell Check and Trie implementation

I have written this code for an Edx course called CS50x (a beginner course). This problem set required me to write a program which: loaded a dictionary into some sort of data structure (I choose to ...
2
votes
1answer
83 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 ...
6
votes
1answer
142 views

RSS feed parser

I've just started learning Swift. I started with an example of RSS feed parser. I have a wrapper class written in Objective-C which converted the XML response into ...
1
vote
2answers
305 views

The efficiency of looping over nested dictionaries in Python

How to make the following code more efficient? ...
7
votes
1answer
83 views

Is this implementation of persistence OK?

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
1answer
45 views

Optimizimg ugly if else loop in python [closed]

So, I`m getting some values from large nested dictionary. s_copy['productStyleVariantSizeInfo']['sizeDimension2SizeOptions'] and f_copy['productStyleVariantSizeInfo']['sizeDimension2SizeOptions'] ...
3
votes
2answers
325 views

Check winner in a Tic Tac Toe game

I have the below code to check for a winner in a Tic Tac Toe game. I'm wondering if this is a good approach, and if there is a better way of doing this (maybe by monitoring the state of the board). ...
0
votes
1answer
41 views

For and if loops in Python math game [closed]

I'm trying to get my program to iterate through a loop after a person gets the correct answers to the first question. I feel like there is a better way to do things syntactically. ...
1
vote
2answers
62 views

Validate fields in Python dictionary using dictionary of lambdas

I would love some feedback on this. I use it to validate web-form objects before persisting them in the dangerously-lazy MongoDb. I have a class and many validators for each of my collections. Is ...
13
votes
1answer
191 views

Python Dictionary Black Magic

I am defining a subclass of a the python dictionary object mpCmd where every item is converted to a lambda. The intended usage is that every item in the dictionary ...
2
votes
3answers
73 views

How can I optimize this hash string function?

I'm writing a function which gets two strings and a number k as an input, and outputs a string with length k which is present in ...
5
votes
3answers
195 views

Is there a simpler way to find winners when there is a tie?

Background: I have a Python script which parses a complicated CSV generated on election nights. Each row of the CSV represents a race. As I loop through the races, I store the candidates for each ...
2
votes
2answers
56 views

Managing and searching objects using tags

I wonder Is it appropriate to hide imported classes (collections and UserDict in this case) from Python IDE (e.g. IPython)? Is there a more efficient algorithm/implementation? Please feel free to ...
1
vote
1answer
92 views

Is this use of ConcurrentDictionary truly thread safe?

I'm working on some teaching examples showing the perils of accessing the Dictionary class concurrently. In the code below each function is designed to do a word count across a number of files. ...
4
votes
1answer
68 views

Output of 'ldd' to dictionary

I want to use the output of the terminal command ldd: ...
5
votes
4answers
337 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: ...
5
votes
2answers
91 views

Geometry table for use in regexes

I have been teaching myself Python 3. I watched a video on YouTube entitled "stop writing classes". The Gtable class doesn't even have an init function, so I can't help but wonder if I should have ...
3
votes
1answer
53 views

Building a dict/list of lists

I have code which is matching features within regions. The first thing it does it matches features from one region to an entire database of region features. I have a mapping from query feature index ...
2
votes
1answer
58 views

Scraping thefreedictionary.com

Scrape results from thefreedictionary.com ...
6
votes
1answer
61 views

Dictionary<TKey, TValue> Implementation

This class encapsulates a List<KeyValuePair> (see List<T> implementation here, and ...
7
votes
3answers
104 views

Collect and calculate average times from log, then display top 10 longest durations

Here's a novel-length summary of the issue: I'm trying to write a VB.net program to help me collect remote site statistics from system-generated logs, but I'm a little like a carpenter who only knows ...
7
votes
2answers
212 views

Game passive skill system

I'm trying to create some easily accessible database of different skills. General idea is that every skill should do something different and be able to act on different things (ex. one skill which ...
10
votes
3answers
137 views

Refactoring if-else structure with elements of dict

I have code which gets data from a POST request (request.form dict), compares with corresponding attribute in object ...
1
vote
1answer
172 views

Making adding to a dictionary more efficient?

I have the following code and it's taking quite some time to run. I'm getting an Out of Memory Exception due to the high volume of answers there are. Is there any ...
8
votes
3answers
477 views

Scrabble algorithm review and performance suggestions

After finishing Project Euler 24, I decided to make a scrabble type of application using /usr/lib/dict as my dictionary what I cat that into a word file. It does take a few seconds, and the dictionary ...
5
votes
2answers
2k views

Splitting an NSArray into an NSDictionary of array more elegantly

I need to split one NSArray into NSDictionary. Every key in NSDictionary will contain an ...
2
votes
2answers
86 views

Special dictionary

I need a special dictionary that would do as follows: if key is set to more than once, the values are a list of all set values. Such a list is returned as value on get. if key is set only once, it ...
3
votes
1answer
388 views

Recursively convert a list of lists into a dict of dicts

As a challenge to myself, I wrote a solution to this Stack Overflow question. For completeness, the bulk of the question is as follows: Problem Input: ...
3
votes
5answers
2k views

Is there a better, more efficient way than Dictionary(Of Tuple(), MyClass)?

Suppose I have data coming from different sources that tells me information about a large group of stores that has the following (just an example): Necessary to define what store we're dealing with: ...
0
votes
1answer
382 views

Copying Dictionary collection into an array [closed]

Hi I want to minimize the following code: ...
3
votes
2answers
459 views

Test if two IDictionary objects contain the same values

I'm adding a function to my test library to assist in testing if two IDictionary objects contain the same keys/values. I need the method to be generic and support ...
0
votes
1answer
701 views

opening a text file and building a dictionary

Need to write a function that takes an open file as the only parameter and returns a dictionary that maps a string to a list of strings and integers. each line in the text will have a username, ...
3
votes
2answers
111 views

Word analysis on input from a file

How do I improve the below code, which takes input from a file and does some word analysis? I find a lot of redundancy in it. I want to know a better way of implementing it. ...
6
votes
3answers
253 views

How best to differentiate boolean values in a long list?

I have a large C# Dictionary of string keys and boolean values. Background on the reason for it is this: my program builds up a bunch of the same objects from two different sources, and then compares ...
3
votes
1answer
142 views

Prime number dictionary

I attempted to write a read-only dictionary, containing primes: ...
1
vote
1answer
2k views

Proper way to compare two Dictionaries [closed]

I am implementing an IEqualityComparer for Dictionary objects and am looking for input on a couple of different approaches. I define equality in this case to be that both dictionaries contain the same ...
1
vote
2answers
101 views

Optimization of a while-loop searching for words in a dictionary

This is my first question here. I'm using an open source program called MElt which lemmatize (give the lemma example:giving-->give) of words. MElt works on Linux and its programmed in Perl and ...
2
votes
2answers
175 views

Python code snippet could probably be more elegant

I'm looking to let people define arbitrarily nested lists of lists and return a random json document for them. Right now the assumption is that if you have a structure like this: ...
1
vote
2answers
257 views

Making a 2D dict readable

I am building a 2d dictionary with an altered list at the end Afterwords I want to find the min of each list. Is there a better way to do it? Better being faster or at least less of an eyesore. ...
1
vote
3answers
183 views

A Better For Loop

I'm very new to Python, and have a feeling that there's a much better way to implement the following code. It works, I'd just like to clean it up a bit. The purpose is just to create a dictionary with ...
5
votes
1answer
83 views

Load drinks and their ingredients into dictionaries

I'm working on a web application using bottle, and it is, at this point, functional. The gist of it is that I have a database of drinks, with associated IDs, and associated sets of ingredients. the ...
2
votes
1answer
986 views

Setting variable if it doesn't exist in Dictionary [closed]

I was wondering if this was good design from client side calls. In the event that the key doesn't exist, go ahead and add it. ...
2
votes
3answers
4k views

Set a default if key not in a dictionary, *or* value is None

Let's say I have a key 'messages' that is usually a list, but might be None, or might not be present. So these are all valid inputs: ...
7
votes
1answer
888 views

Simple trie implementation in JavaScript

After experimenting with a sorted trie implementation in C, I felt that I understood tries pretty well, but was having trouble explaining how they work. Since the C code was based on existing code, I ...