dictionary

Concatenating Two Properties for Display in a DropDownList

Background In our last adventure, I was attempting to properly show a Dictionary<Foo, Bar<T>>. Thanks to the helpful answers in that post, I realize I had been going about it in the wrong way. Problem In today's adventure, I've been trying to get two specific properties from the List<T> in the last question to display. Each List h...

Deserialization problem with DataContractJsonSerializer

I've got the following piece of JSON: [{ "name": "numToRetrieve", "value": "3", "label": "Number of items to retrieve:", "items": { "1": "1", "3": "3", "5": "5" }, "rules": { "range": "1-2" } }, { "name": "showFoo", "value": "on", "label": "Show foo?" }, { "name...

Collection was modified; enumeration operation may not execute.

I can't get to the bottom of this error, because when the debugger is attached, it does not seem to occur. Below is the code. This is a WCF server in a Windows service. The method NotifySubscribers is called by the service whenever there is a data event (at random intervals, but not very often - about 800 times per day). When a Windows...

How can I retrieve random words from the iPhone's dictionary?

Is there a way to retrieve words randomly from the built in Dictionary through the SDK? I can provide my own list of words but using the built in Dictionary allows for easy localization. ...

Python: Sort a dictionary by value

I have a dictionary of values read from 2 fields in a database: a string field and a numeric field. The string field is unique so that is the key of the dictionary. I can sort on the keys, but how can I sort based on the values? Note: I have read this post 72899 and probably could change my code to have a list of dictionaries but since...

Python function: Find Change from purchase amount

I'm looking for the most efficient way to figure out a change amount (Quarters, dimes, nickels, and pennies) from a purchase amount. The purchase amount must be less than $1, and the change is from one dollar. I need to know how many quarters, dimes, nickels, and pennies someone would get back. Would it be best to set up a dictionary? ...

StringDictionary vs Dictionary<string, string>

Does anyone have any idea what the practical differences are between the System.Collections.Specialized.StringDictionary object and System.Collections.Generic.Dictionary? I've used them both in the past without much thought as to which would perform better, work better with Linq, or provide any other benefits. Any thoughts or suggestio...

Linq query to return a Dictionary<string, string>

I have a collection of MyClass that I'd like to query using linq to get distinct values, and get back a Dictionary as the result - but can't figure out how I can do it any simpler than I'm doing below. Does anyone have some cleaner code that I can use to get the Dictionary as my result? var desiredResults = new Dictionary<string, s...

Cannot cast Dictionary ValueCollection to IEnumarable<T>. What am I missing?

var _pool = new Dictionary<Type, Dictionary<EntityIdType, Object>>(); public IEnumerable<EntityType> GetItems<EntityType>() { Type myType = typeof(EntityType); if (!_pool.ContainsKey(myType)) return new EntityType[0]; //does not work, always returns null // return _pool[myType].Values; as IEnumerable<EntityType...

Dictionaries in Python

I am trying to get to speed on the use of dictionaries. I spent three hours last night searching the web for examples similar to some of the things I am trying to do. For example, suppose I have two dictionaries (actually I have two lists of dictionaries). d1={key1:1, key2:2} d2={key1:1, key2:'A', key4:4} I want to update d1 so it...

ThreadSafe Dictionary... Key Value Pairs Enumerable? (.net)

I'm perusing (considering writing my own thread safe dictionary) I found the following implementation. http://devplanet.com/blogs/brianr/archive/2008/09/26/thread-safe-dictionary-in-net.aspx It looks pretty good generally, but there's one thing that confuses me. The following: Cannot enumerate a threadsafe dictionary. Instead, enum...

Using an object as a generic Dictionary key in .net

If I want to use objects as the keys for a Dictionary, what methods will I need to override to make them compare in a specific way? Say I have a a class which has properties: class Foo { public string Name { get; set;} public int FooID {get; set;} ... } And I want to create a: Dictionary<Foo, List<Stuff>> I want Foo ob...

Python - How to calculate equal parts of two dictionaries?

I have a problem with combining or calculating common/equal part of these two dictionaries. In my dictionaries, values are lists: d1 = {0:['11','18','25','38'], 1:['11','18','25','38'], 2:['11','18','25','38'], 3:['11','18','25','38']} d2 = {0:['05','08','11','13','16','25','34','38','40', '43'], 1:['05', '...

What is the best data structure for this in-memory lookup table?

I need to store a lookup table as an instance member in one of my classes. The table will be initialized when the object is constructed. Each "row" will have 3 "columns": StringKey (e.g., "car") EnumKey (e.g., LookupKeys.Car) Value (e.g, "Ths is a car.") I want to pick the data structure that will yield the best performance for doin...

How to manually add data to a DataGrid in Silverlight

I have found that datagrid columns can be dynamically created and bound in Silverlight. However I can't find a way to bind data to those columns. If I try to bind any type of object with AutoGenerateColumns = true, then the names of each property of the object get added as columns and the object information is displayed in the grid in a...

How do I re-map python dict keys

I am working on a program that (among other things) reads a CSV file in (it gets stored as an array of dicts in the form [{col1:data1a,col2:data2a},{col1:data1b,col2:data2b}] ). For each row, as part of other processing, I need to remap those keys to user entered values, which are provided in another dict so they can be used as parameter...

Using dictionary data structure in lex/yacc

I'm writing an assembler for a microprocessor I'm creating using lex/yacc. I'd like to implement labels in my assembler code, and I thought a good way to do this would be to have a dictionary of labels in the form {name:line#}. I could then check when inserting a label, if it's already defined, its an error. So how can I use a dictiona...

Python - Acquire value from dictionary depending on location/index in list

Hi Everybody, From MySQL query I get data which I put into a dictionary "d": d = {0: (datetime.timedelta(0, 25200),), 1: (datetime.timedelta(0, 25500),), 2: (datetime.timedelta(0, 25800),), 3: (datetime.timedelta(0, 26100),), 4: (datetime.timedelta(0, 26400),), 5: (datetime.timedelta(0, 26700),)} I have a list "m" with...

How do I create a unique value for each key using dict.fromkeys?

First, I'm new to Python, so I apologize if I've overlooked something, but I would like to use dict.fromkeys (or something similar) to create a dictionary of lists, the keys of which are provided in another list. I'm performing some timing tests and I'd like for the key to be the input variable and the list to contain the times for the r...

Dictionaries in Project Structure

Hello. I am wrapping up an application where I am using a lot of Dictionary classes to store Function and Action delegates. I am now refactoring my project a bit and cleaning code. My question is where do or would you put your Dictionary classes in your project structure? Right now, they are located within the calling class source files ...