dictionary

C# - Need Suggestions on Improving a Section of Code

I have a function that receives three different "people" objects and generates a new "compatibility" object based on the combined values in the "people" objects. However, about 1/3 of the time the three "people" objects that it receives as input are the same as one before, though possibly in a different order. In these cases I do NOT wa...

List a dictionary

In a list appending is possible. But how I achieve appending in dictionary? Symbols from __ctype_tab.o: Name Value Class Type Size Line Section __ctype |00000000| D | OBJECT|00000004| |.data __ctype_tab |00000000| r | OBJECT|00000101| |.ro...

YAML: dictionary with empty value

How do I write in YAML a dictionary (map) where one key has the empty string as its value? ...

Python dictionary deepcopy

Hello there, I was wondering in how does exactly deepcopy work in the following context: from copy import deepcopy def copyExample: self.myDict = {} firstPosition = "First" firstPositionContent = ["first", "primero"] secondPosition = "Second" secondPositionContent = ["second"] self.myDict[firstPosition] = fir...

C# Equivalent of Java IdentityHashMap

As far as i know, there is no direct equivalent in C#. My current idea is to use a Dictionary with a custom IEqualityComparer, that checks for reference equality. However, this seems to lose the advantage gained by hashing. Is there a way to get an individual hashcode out of every different object? Or is this impossible and I should use...

Standard Thread safe .Net Dictionary

MSDN points out that mutating access to the .NET Dictionary<K,V> type is not thread safe. Is there a standard thread safe version? Note: "No there is not" is a valid answer if it is true. In that cases (and it seem to be) I'll go off and do the lock thing. Almost Duplicate What’s the best way of implementing a thread-safe Dictionary...

Is there a way to set multiple defaults on a Python dict using another dict?

Suppose I've got two dicts in Python: mydict = { 'a': 0 } defaults = { 'a': 5, 'b': 10, 'c': 15 } I want to be able to expand mydict using the default values from defaults, such that 'a' remains the same but 'b' and 'c' are filled in. I know about dict.setdefault() and dict.update(), but each only do half of what I want ...

C#/.NET: Dictionary memory usage

I've got a generic Dictionary that holds a bunch of data. I'd like to start removing items (I know how to determine which ones) when the size of the Dictionary starts taking up too much memory. What's the best way for my program to monitor the RAM used by this Dictionary? Each item in the Dictionary is a variable size. ...

Can I Pass Dictionary Values/Entry and Keys to function

I am writing a function and intended to use a dictionary key and its value as parameters. For example: testDict={'x':2,'xS':4} def newFunct(key,testDict['key']): newvalue=key+str(testDict['key']) return newValue for key in testDict: newValue=newFunct(key,testDict[key]) print newValue I get a SyntaxError: invalid sy...

const Dictionary in c#

I have a class in C# that contains a Dictionary, which I want to create and ensure nothing as added, edited or removed from this dictionary as long as the class which contains it exists. readonly doesn't really help, once I tested and saw that I can add items after. Just for instance, I created an example: public class DictContainer { ...

DataGridView bound to a Dictionary.

I have a Dictionary that contains items and prices. The items are unique but slowly get added and updated through the lifetime of the app (i.e. I don't know the item strings in advance). I would like to bind this structure to a DataGridView so I can show updates on my Form, something like: Dictionary<string, double> _priceData = new Dic...

Why can't I pass a direct reference to a dictionary value to a function?

Earlier today I asked a question about passing dictionary values to a function. While I understand now how to accomplish what I was trying to accomplish the why question (which was not asked) was never answered. So my follow up is why can't I def myFunction(newDict['bubba']): some code to process the parameter Is it simply beca...

What is the known performance difference between a Microsoft.VisualBasic.Collection and a .NET System.Collections.Generic.Dictionary(Of TKey, TValue)?

I'm working on a fairly large project for a trading company in Philadelphia. The company utilizes automated trading algorithms which process streaming quotes and send out quotes for hundreds of products dozens of times per second. Obviously, performance is a significant concern. (Which makes me question why we're using VB.NET, but that's...

Using Hashtables/Dictionaries with string keys & Case Insensitive Searching

Wondering if this is possible. We have an 3rd Party library that contains identification information about users... The main interaction with the library is through a HashTable which is keyed with a string, and returns an Object Graph of information for that key. The problem is, the key is obviously Case Sensitive, but what we get fro...

asp.net: how to access to each element of dictionary without using key?

i want to access each object of my dictionary Dictionary with int index. hw to do that. ...

Ordering a list of dictionaries in python

I've got a python list of dictionaries: mylist = [ {'id':0, 'weight':10, 'factor':1, 'meta':'ABC'}, {'id':1, 'weight':5, 'factor':1, 'meta':'ABC'}, {'id':2, 'weight':5, 'factor':2, 'meta':'ABC'}, {'id':3, 'weight':1, 'factor':1, 'meta':'ABC'} ] Whats the most efficient/cleanest way to order that list by weight then factor (numericaly)...

Which PEP governs the ordering of dict.values()?

When you call dict.values() the order of the returned items is dependent on the has value of the keys. This seems to be very consistent in all versions of cPython, however the python manual for dict simply states that the ordering is "arbitrary". I remember reading somewhere that there is actually a PEP which specifically states the exp...

Getting key from value in .Net collection

Hi, I am using a StringDictionary to store key value pairs. I need to use the keys and values interchangeably i.e. I should be able to get the key from the value as in my case the values will be distinct. Is there a direct way I could do it (without looping)? Or if there is any other collection I could use to achieve this? Currently I...

Is there any character limitation in Dictionary Keys?

In .NET can I use any string as a dictionary key? This is part of a templating engine and I'm planning allow users to add their custom headers and values. Headers will be something like "Value of X" or "Summary of Analyse & XYZ Reports", I'm worried if they would get an exception in a rare character or something like that. I assume th...

Performance of Dictionary(Of String, SomeReferenceType) in VB.NET

How does performance for reading/adding values from/to Dictionary(Of String, SomeReferenceType) depend on the number of records already entered? I mean, does time increase as O(1), O(log n), O(n) when n goes to be large, or in some other way? Dim index As New Dictionary(Of String, SomeReferenceType) ' N entries added in a loop ' ... D...