Questions tagged [dictionary]

The tag has no usage guidance.

Filter by
Sorted by
Tagged with
-1 votes
1 answer
136 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 ...
user avatar
  • 115
1 vote
2 answers
345 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 ...
user avatar
-4 votes
4 answers
1k 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 ...
user avatar
  • 1,339
0 votes
1 answer
2k 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 ...
user avatar
  • 127
-2 votes
1 answer
60 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 ...
user avatar
  • 97
0 votes
1 answer
638 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: ...
user avatar
  • 308
1 vote
3 answers
300 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": ...
user avatar
-2 votes
1 answer
147 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 ...
user avatar
  • 432
7 votes
3 answers
425 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 ...
user avatar
  • 3,307
31 votes
9 answers
28k 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 ...
user avatar
  • 1,477
-1 votes
3 answers
196 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 ...
user avatar
-1 votes
1 answer
536 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 ...
user avatar
-1 votes
4 answers
1k 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 ...
user avatar
-3 votes
1 answer
79 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 ...
user avatar
  • 159
32 votes
5 answers
18k 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 ...
user avatar
  • 511
3 votes
5 answers
13k 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 ...
user avatar
  • 157
1 vote
1 answer
393 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("...
user avatar
  • 141
2 votes
1 answer
2k 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 ...
user avatar
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)...
user avatar
  • 145
0 votes
1 answer
173 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 ...
user avatar
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 ...
user avatar
  • 3
20 votes
3 answers
9k views

In Python 3.4+, 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 ...
user avatar
3 votes
2 answers
6k 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: # ...
user avatar
5 votes
2 answers
5k 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 ...
user avatar
2 votes
1 answer
5k 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 ...
user avatar
3 votes
2 answers
655 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 ...
user avatar
  • 521
3 votes
2 answers
280 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, ...
user avatar
4 votes
2 answers
198 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: ...
user avatar
  • 323
2 votes
2 answers
15k 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. ...
user avatar
  • 153
7 votes
1 answer
20k 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 ...
user avatar
4 votes
1 answer
273 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.
user avatar
2 votes
2 answers
608 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 ...
user avatar
  • 123
0 votes
1 answer
156 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}...
user avatar
  • 1,799
0 votes
1 answer
914 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 ...
user avatar
4 votes
2 answers
10k 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) ...
user avatar
-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 ...
user avatar
  • 189
-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 ...
user avatar
  • 2,225
9 votes
3 answers
25k 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 ...
user avatar
  • 263
21 votes
1 answer
55k 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 ...
user avatar
4 votes
2 answers
1k 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 ...
user avatar
0 votes
2 answers
677 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 ...
user avatar
  • 123
3 votes
2 answers
37k 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 ...
user avatar
  • 211
0 votes
3 answers
480 views

Class or Dictionary

I want to create a immutable Scale class in C#. public sealed class Scale { string _Name; string _Description; SomeOrderedCollection _ScaleValueDefinitions; Unit _Unit // ...
user avatar
0 votes
1 answer
297 views

Algorithm for compression of a dictionary (words and definitions)

The theoretical situation is this: Let's say that we have a digital dictionary (by which I mean a traditional list of words and definitions, not an associative array). For the sake of simplicity, ...
user avatar
0 votes
1 answer
3k views

Fast lookup hash map implementations

I'm in the process of implementing a programming language on top of LLVM. For my polymorphic system, I'm looking for suggestions for a ultra-fast dictionary. I am not concerned with insert time, as ...
user avatar
3 votes
3 answers
6k views

Try to find a word in the dictionary that has most letters given

I recently came across an algorithm design problem that I'd like some help with: Given some letters, for example a,e,o,g,z,k,l,j,w,n and a dictionary of words. Find a word in the dictionary that has ...
user avatar
  • 139
91 votes
5 answers
235k views

Why store a function inside a python dictionary?

I'm a python beginner, and I just learned a technique involving dictionaries and functions. The syntax is easy and it seems like a trivial thing, but my python senses are tingling. Something tells me ...
user avatar
  • 1,029
6 votes
2 answers
1k views

History of Associative Array?

In quite a lot of modern scripting languages (e.g. Perl, Python, Ruby, PHP, Lua, JavaScript), associative arrays are supported as a primitive or first-class data type (with various names like map, ...
user avatar
  • 215
6 votes
2 answers
997 views

What is a good way to keep track of strings for dictionary lookups?

I am working through the Windows 8 app tutorial. They have some code about saving app data like so: private void NameInput_TextChanged(object sender, TextChangedEventArgs e) { ...
user avatar
  • 249
15 votes
5 answers
54k views

Efficient methods for storing tens of millions of objects for querying, with a high number of inserts per second?

This is basically a logging/counting application that is counting the number of packets and counting the type of packet, etc. on a p2p chat network. This equates to about 4-6 million packets in a 5 ...
user avatar
  • 253