Questions tagged [dictionary]
The dictionary tag has no summary.
62 questions
0
votes
1
answer
158
views
Optimal way to avoid iterating through each row in a dictionary of data/arrays?
I have an excel macro that imports daily share price files, and finds the highest price for a share after a given date.
Each of these daily stock price files has ~1000 rows of data. Currently I have ...
1
vote
1
answer
114
views
Python: mapping the content of a structured text file to dictionary tree
I'm looking for a method to map the content of a structured text file to a nested dictionary (dictionary tree). The text file consists of (nested) sections with each section starting with the pattern ...
3
votes
5
answers
2k
views
C# List vs Dictionary cost vs benefit with complex keys
I am designing a program and I am looking to decide over a Dictionary vs a List.
Since I know I have unique values per item I imagined a Dictionary/List that looks like:
Dictionary<(int k1, string ...
1
vote
1
answer
139
views
Long dictionary/map key vs shorter key + equality check for an auth cache
I'm implementing an API key based authentication scheme and I'm caching valid API key entries (hash, scope etc.) in a memory cache. For the cache key, I had been using the first 8 characters of the ...
1
vote
1
answer
105
views
How to reuse parts of a Trie data structure (like a Trie DAG)?
I am playing around with a cross-language spell-check sort of thing, and am still in the prototyping/ideation phases. Basically I have thought of something like a Trie data structure, but I keep ...
7
votes
1
answer
3k
views
Why are there two ways to retrieve values from a dictionary in Python?
In Python there are basically two ways to get a value from a dictionary:
dictionary["key"]
dictionary.get("key")
Is there any - maybe historical - reason for this behavior?
I ...
0
votes
0
answers
142
views
Is it a code smell to have to query a dictionary for a key whose value matches some criteria?
I am working on a ChildModelListSheetHandler, that has a childModelListDict.
As what you're probably thinking, it maps the foreign keys that are the IDs of the parent models, to the list of child ...
2
votes
1
answer
872
views
Elegant way to handle two options, when both is also an option
In the simplest case, I have some code where the user may want to do one thing (a), another thing, (b), or both (a+b).
The options are reasonably complex and have their own functions, but I would like ...
0
votes
1
answer
2k
views
Query language for python dictionary
I have a list of python dictionaries (let's assume each dict is flat for the time being). The keys are all strings and the values are strings or real numbers. I would like the user to have the freedom ...
1
vote
2
answers
2k
views
Why it is possible to specify a value comparer for ImmutableDictionary<TKey, TValue>?
What is the intended usage of the ImmutableDictionary<TKey,TValue>.ValueComparer property?
Why is it useful being able to compare dictionary values by using a specified equality semantic?
I ...
-4
votes
4
answers
3k
views
Time efficient way to count pairs in an array whose sum is divisible by a specific number?
Given an array of integers, we want to find how many explicit pairs can be made such that their sum is divisible by 60. The pairs are not necessarily non-unique.
For example, let's say the input into ...
0
votes
1
answer
3k
views
What is the space complexity of a Python dictionary?
If python dictionaries are essentially hash tables and the length of hashes used in the python dictionary implementation is 32 bits, that would mean that regardless of the number of key-value pairs ...
-2
votes
1
answer
88
views
Find circular references of first order (bi-directional referencing)
I have million of objects, each with an array smaller than 10 elements, which are the names of other objects in the dataset.
Basically
{
a:[b,c,d,],
b:[c,d,e],
c:[a,e,f],
...
e:[a,b,c]
}
will ...
0
votes
1
answer
2k
views
Unpacking python dictionaries, or list comprehension, or …
my_dict = { 1: 11, 2: 12, 3: 13 }
If I want to work on the list of keys from my_dict there appear to be (at least) three ways to do this in Python >3.5 (i.e. on or after PEP 448)
List Comprehension:
...
1
vote
3
answers
558
views
Are 'array elements' and 'array values' the same?
Array := {"title": "Book Title", "author": "John Doe"}
Some people use the following terminology:
title and author are keys.
Book Title and John Doe are values.
"title": "Book Title" and "author": "...
-2
votes
1
answer
196
views
Map synchronization algorithm
Say I have two Map instances in JavaScript (or HashMap in Java, or Dictionary in C#), A and B. I want to synchronize B to A, so that B is a copy of A. I can't copy the reference and I don't want to ...
8
votes
3
answers
2k
views
Pointers vs keeping indices of objects stored in a central (associative) array?
Until recently I used to think that it was preferred to reference objects by pointers or references than to keep objects in some sort of a central, authoritative array or dictionary and only keep ...
35
votes
9
answers
51k
views
Is there a better way to use C# dictionaries than TryGetValue?
I find myself often looking up questions online, and many solutions include dictionaries. However, whenever I try to implement them, I get this horrible reek in my code. For example every time I want ...
-1
votes
3
answers
459
views
When to use a reserved word, null or undefined as a key in an object?
I have a case where I have a dictionary object and a value with no key.
The object can have the system values and then a user value. I have to store that value.
I could use a reserved word or I ...
-1
votes
1
answer
828
views
Difference between data Dictionaries and diagrams in SDD
I am writing a software specification and I got confused with the data dictionaries section.
is it a full detail of the interfaces and stored models ( like of a database ) or a just a second step of ...
-1
votes
4
answers
2k
views
Why can't Dictionary(TKey, TValue) update it's hashcodes?
I've read that an object's hashcode should not change while it is part of a Dictionary.
Because if it changed, there would be no way to find it in the Dictionary.
Why doesn't the Dictionary class ...
-3
votes
1
answer
106
views
Best Data Structure for ordered list of connected users
I have three attributes for a user: connectionId (e.g. "sd4-h4sdg-u4j-a2rr3"), userName, and placeInLine.
I can't think of a single data structure that will handle my scenario of only allowing a ...
32
votes
5
answers
20k
views
When to use a dictionary vs tuple in Python
The specific example in mind is a list of filenames and their sizes. I can't decide whether each item in the list should be of the form {"filename": "blabla", "size": 123}, or just ("blabla", 123). A ...
4
votes
5
answers
14k
views
Why are Python sets and dictionaries not ordered by default?
I understand the difference between ordered and unordered sets, and I understand why for many purposes, we don't need ordered sets. But all set operations are still possible on ordered sets, and sets ...
1
vote
1
answer
1k
views
Enum or dictionary for inmemory parameter
I have a table UserItems {ID, UserID, ItemID}
Items must be in RAM (not in db table).
What is better for this? As enum with attributes or as dictionary of items?:
enum Items
{
[InternalParam("...
5
votes
1
answer
3k
views
What is the difference between the solution that uses defaultdict and the one that uses setdefault?
In Think Python the author introduces defaultdict. The following is an excerpt from the book regarding defaultdict:
If you are making a dictionary of lists, you can often write simpler
code using ...
0
votes
1
answer
3k
views
Comparing Two JSON Files In O(n)
I've got a scenario where I need to compare two JSON files and override one if the values are different. These JSONs also include arrays (i.e. [)
My approach is to traverse one JSON to dictionary O(n)...
0
votes
1
answer
282
views
XML file vs instance variable for storing a dictionary
I want to make a dictionary that stores some values I want to use within my code. Would it be better to use an instance variable to hold the dictionary, or an XML file to hold the dictionary, or ...
0
votes
1
answer
2k
views
What would be a proper implementation of a dictionary in java?
The problem:
Let's say I want to create a java app (currently using java 8) that works like a dictionary. I want the app to give the user the capacity to add and search for words, every word must ...
32
votes
3
answers
15k
views
Why should I use namedtuple over SimpleNamespace when not using dict, they seem very similar
At one point or another you might come over functions with a lot of arguments. Sometimes it makes sense to combine some of the arguments into super-arguments. I've often done this with dicts, but now ...
3
votes
2
answers
7k
views
Which is more pythonic: Checking for existence and not being None, or using truthiness and get() with dicts?
I'm loading a config file. I'm considering the following ways of doing it. Version 1:
config = json.load('myconfig.json')
config_elm = config.get('some_config_elm')
if config_elm is not None:
# ...
6
votes
2
answers
6k
views
Why is there no key specified with .NET KeyNotFoundException?
Why is there no key specified with .NET KeyNotFoundException (in message/property)? Is it because of performance reasons? Is it because when Dictionary finds out there isnt any requested object by the ...
3
votes
1
answer
8k
views
Do you name a dictionary by the key or the value? [closed]
Do you name a dictionary by the key or the value? I have a dictionary that will hold gradient data and the component:
dictionary[gradient] = component;
Do I name it gradientDictionary or ...
3
votes
2
answers
690
views
How to build a class for comparing words in a lexical dictionary?
I'm wanting to create a class that stores words in a set so that I can see if a word belongs to that set or not. I'm not wanting to build ever set every time I instantiate the class, so I'm using what ...
3
votes
2
answers
308
views
Is polymorphism appropriate for modeling natural language form (structure), or is there something better?
Let's take French and Japanese adjectives as simple examples.
French adjectives have gender (masculine or feminine) and number (singular or plural), whereas Japanese nouns have neither. However, ...
4
votes
2
answers
280
views
Implementing a key-sensitive monad bind for key-value Map
Based on the List monad I set out to define Monad instances for the Map type from Data.Map, to perform chained unions and folds on Maps like lists, but with the efficient sorting and merging of Maps:
...
4
votes
2
answers
20k
views
API Design: Should I use strings or an enum for dictionary keys
I am working on an API in C#. I am trying to think about the simplest way to expose my API for consumers of it. In particular, I have a class in my exposed data model that has a dictionary property. ...
7
votes
1
answer
24k
views
Dictionary of dictionaries design in C#
My question: is there a canonical way of creating a dictionary of dictionaries and providing an outer/inner key pair? Is there a NugetPackage out there with an implementation?
In my code, I have now ...
4
votes
1
answer
292
views
Is there a term used for the collection of a key and value in a C# dictionary?
simple question, I want to know if there's a word/term used to describe the collection/pair of a key and value in a C# Dictionary.
2
votes
2
answers
795
views
GPL dictionary usage in commercial application
We have an word game commercial mobile application for which we want to use dictionaries for various languages. Most of them have GPLv3 or CC-NC3 licenses.
We modify the dictionaries: basically, we ...
0
votes
1
answer
199
views
How to understand JavaScript's "delete h[key]" and Python's "del h[key]"?
There is one thing I can't really understand in JavaScript or Python, and that's the delete or del syntax.
In JavaScript:
obj = {ha: 123, hi: 3.14}
delete obj.ha # now obj is {hi: 3.14}...
0
votes
1
answer
1k
views
Algorithm to get all possible forms of a word with varying suffixes [closed]
I'm writing an application in javascript where given a word, I need to get all the possible versions of the word with the suffix being the difference between each form. For example:
"sponsor" should ...
4
votes
2
answers
12k
views
Is there a key/key lookup table type provided in .NET?
It seems like a pretty straightforward thing to add, but I just want to be sure .NET doesn't already provide one and save me from adding unnecessary code:
I need a lookup table (like a Dictionary) ...
-3
votes
2
answers
1k
views
Integer Map Algorithm [closed]
For my project, I need to map integers so that inputting int X will output int Y where both X and Y are defined during runtime.
I've used Dictionary<int,int> in .NET but its memory use is too ...
-3
votes
1
answer
2k
views
Dictionary representation of an object
As python memory model is dictionaries of dictionaries, looks like any object in JavaScript has similar representation.
Below code,
>
foo = {}
makes foo as an empty dictionary {}. fine.
If code ...
10
votes
3
answers
33k
views
What are the advantages of linear probing over separate chaining or vice-versa when implementing hash tables?
I've been brushing up on algorithms and reviewed these two methods of implementing hash tables. It seems like they largely have similar performance characteristics and memory requirements.
I can ...
27
votes
1
answer
74k
views
Efficiency of C# dictionaries
C# dictionaries are a simple way to find if something exists etc etc. I have a question though on how they work. Let's say instead of a dictionary I use an ArrayList. Instead of using ContainsKey (or ...
7
votes
2
answers
3k
views
In Python, is there any difference (apart from a few listed exceptions) between classes and dictionaries?
My logic goes like this:
def A(val):
return {'a':val}
print(A(7)['a'])
is the same as
class A:
def __init__(self, val):
self.a = val
print(A(7).a)
Obviously, there are problems and ...
0
votes
2
answers
739
views
Critique the Structure of my Horse Racing Betting Platform
I am creating a program (mostly just for fun) that displays live prices for horse racing markets and the prices that several models predict they should be. I am very interested in the optimal way to ...
3
votes
2
answers
39k
views
Efficient solution for dictionary updates
Let's start with the problem:
There is a large dictionary X that contains {key, value} pairs, i.e.:
X = [{100, 10}, {101, 0}, {103, 0}, {106, 2}, {110, 1}]
Every t seconds, X has to be updated with ...