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

8
votes
1answer
83 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
34 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
38 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
39 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 ...
1
vote
2answers
71 views

Code to generate a dictionary from two lists

I created a script to perform a union on 2 lists: keys and words. I needed to create a dictionary from them. If there are more keys than words, missing words are replaced with "None". Any excess words ...
3
votes
1answer
89 views

Read from csv file, transform to dictionnary

First of all, here's the code I'm working on: ...
4
votes
2answers
79 views

Traversing and printing complex Dictionary types (Scripting.Dictionary) - Dictionary inside of a Dictionary

Based on this SO post - also reposted on vba4all.com with a few more details and explanations. Please notice there currently is no error handling whatsoever as I didn't analyse and consider any traps ...
2
votes
1answer
35 views

Fuzzy matching dict keys

What do you think of this idea? It's supposed to be a dict that makes a reasonable guess at the key you were trying to access for getters and deleters. Setters should be untouched. Similar to how ...
1
vote
0answers
34 views

Using URLs and RegEx for web scraper from a dictionary [closed]

I have dozens of functions which GET/POST to some URLs and extract data using RegEx. The URLs and regular expressions were hard-coded earlier but now I moved all of them to a dictionary. I then saw ...
2
votes
1answer
50 views

A function to convert FASTA .txt to a dictionary

I'd like feedback on my function to convert FASTA data to a dictionary in Python. Here's an example of FASTA text: ...
6
votes
3answers
127 views

Convert dict entries to sets and lists

Can you please tell me if there is a better way to do this? ...
11
votes
3answers
253 views

Using a Dictionary to retrieve BOOL values

I have some values pulled from a web service giving me a bool value for a key. I did it this way, but feel like it is repeating without need. How can I refactor this? Please note that the key on ...
3
votes
1answer
77 views

Creating a fast Android dictionary (word counts)

This is a follow-up of my question here: I am currently working on an application for various statistics. One task is to analyse a good amount of sentences for their word counts. The specifications ...
3
votes
1answer
54 views

Merging values with lists as flat-lists

I'm merging dictionaries together in series. Each one may/may not have lists as values. I'd like to merge indefinitely and, have the final merged dictionary contain only flat lists as values. Any ...
3
votes
0answers
100 views

Multi-dictionary API using Python Flask-RESTful

I'm working on a simple online dictionary tool, using Python Flask-RESTful as the RESTful API backend. The dictionary tool is modular, it can handle multiple dictionaries, implemented as independent ...
2
votes
1answer
42 views

A module to display, update and save a dictionary as .csv v2.0

I'd like feedback on my revised code after my previous question. The goal is to create a module which can display, update, save dictionaries as .csv files. I'll use this in another program to update ...
7
votes
1answer
71 views

A simple dictionary tool, extensible with plugins

I'm working on a simple dictionary tool, with a base class that can be extended by plugins to represent different dictionaries. The base class does most of the heavy lifting: it keeps the index of all ...
3
votes
3answers
176 views

A program to display, update and save a dictionary as .csv

I'm now looking for feedback on v2.0 of this program instead. I'd like some feedback about my code. What bad habits do I have? What advice could help me write more Pythonic? I'm trying to write a ...
7
votes
2answers
354 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
54 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
56 views

Convert 2D list to dict of list of index

I have a 2D list like this: ...
5
votes
4answers
411 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
96 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
493 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
135 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
222 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
445 views

The efficiency of looping over nested dictionaries in Python

How to make the following code more efficient? ...
7
votes
1answer
88 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
61 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
396 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
155 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
90 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
219 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
80 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
211 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
65 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
141 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
110 views

Output of 'ldd' to dictionary

I want to use the output of the terminal command ldd: ...
5
votes
4answers
362 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
92 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
54 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
65 views

Scraping thefreedictionary.com

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

Dictionary<TKey, TValue> Implementation

This class encapsulates a List<KeyValuePair> (see List<T> implementation here, and ...
8
votes
3answers
114 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
251 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
149 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
199 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
671 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
3k 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
88 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 ...