Questions tagged [dictionary]
56 questions
96
votes
5 answers
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 this is a deep and very pythonic concept and I'm…

mdeutschmtl
- 1,079
- 1
- 8
- 6
53
votes
4 answers
What is the difference between a hash and a dictionary?
What is the difference between Hash and Dictionary?
Coming from a scripting background, I feel that they are similar, but I wanted to find out the exact differences. Googling did not help me much.

Sairam
- 641
- 1
- 5
- 8
32
votes
9 answers
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 to use a value:
int x;
if…

Adam B
- 1,506
- 2
- 12
- 20
32
votes
5 answers
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 dictionary seems more logical to me because to…

clb
- 521
- 1
- 4
- 3
26
votes
3 answers
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 I'm looking at better ways of doing it.
I'd like…

André Christoffer Andersen
- 1,315
- 2
- 12
- 18
26
votes
1 answer
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 an equivalent method in another language) I loop…

John Demetriou
- 672
- 1
- 10
- 18
16
votes
5 answers
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 minute period. And because I only take a "snapshot"…

Josh
- 263
- 1
- 2
- 4
11
votes
4 answers
Practical size limits of a Hashtable and Dictionary in C#
What are the practical limits for the number of items a C# 4 Dictionary or Hashtable can contain and the total number of bytes these structures can reasonable contain?
I'll be working with large numbers of objects and want to know when these…

JoeGeeky
- 811
- 4
- 10
- 23
9
votes
3 answers
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 think of some disadvantages to linear probing --…

Casey
- 263
- 1
- 3
- 9
7
votes
3 answers
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 indices or keys of members of such an array.
However,…

gaazkam
- 3,517
- 3
- 19
- 35
7
votes
1 answer
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 a few places where I have a property like…

Frank Bryce
- 938
- 1
- 6
- 15
6
votes
2 answers
Should I use a Class or Dictionary to Store Form Values
I am working on a C# .NET Application, where I have a Form with lots of controls. I need to perform computations depending on the values of the controls. Therefore, I need to pass the Form values to a function and inside that function, several…

Shamim Hafiz - MSFT
- 4,123
- 7
- 38
- 46
6
votes
2 answers
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, dictionary, hash, etc.) in a very convenient syntax,…

ZhangChn
- 215
- 1
- 7
6
votes
2 answers
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)
{
Windows.Storage.ApplicationDataContainer…

Justin
- 259
- 1
- 6
5
votes
2 answers
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 hash it already doesnt know the context of the…

NeverStopLearning
- 323
- 1
- 3
- 7