dictionary

python tuple to dict

For the tuple, t = ((1, 'a'),(2, 'b')) dict(t) returns {1: 'a', 2: 'b'} Is there a good way to get {'a': 1, 'b': 2} (keys and vals swapped)? I'm wanting to be able to return 1 given 'a' or 2 given 'b', perhaps converting to a dict is not the best way. ...

get values from nested Dictionary using LINQ. Values of Dictionary are list of lists.

How to get values from nested Dictionary using LINQ. Keys in the Dictionary are integer. Values of Dictionary are list of lists. Seconday level list is a list of array holding integer value. Thanks in advance. ...

Linq query on Dictionary<int, double> type

I have a dictionary of type Dictionary<int, double> and want to eliminate values equal to a certain value. At the moment I have Dictionary <int, double> dict = GetDictionary(); dict = dict.Where(x => x.Value != 100).Select(x => x); And am getting the error: Cannot implicitly convert type 'System.Collections.Generic.IEnumerable<Syste...

ActionScript - Dictionaries Best For Adding Bool Properties To Non-Dynamic Objects?

i'm currently using a dictionary to associate a boolean to my (non-dynamic) sprites, but i would like to know if there is a smarter way of doing this? i could just use MovieClips to assign my properties instead of Sprites since MovieClips are dynamic, but i will not be using any of the MovieClip properties or functions so it comes down ...

Disadvantages of using anonymous types in place of dictionaries?

I wrote this function private string BuildXPathQuery(string prefix = "descendant::", string tag = "*", object attrs = null) { StringBuilder sb = new StringBuilder(prefix); sb.Append(tag); if (attrs != null) foreach (var a in attrs.GetType().GetProperties()) sb.Append(string.For...

Testing for equality between dictionaries in c#

Assuming dictionary keys and values have their equals and hash methods implemented correctly, what is the most succinct and efficient way to test for equality of two dictionaries? In this context two dictionaries are said to be equal if they contain the same set of keys (order not important), and for every such key, they agree on the va...

.NET "invertible" dictionary where keys and values are exchangeable

Is there any .NET type that would represent a set of key-value pairs where each key will only be paired with a single value (like a regular Dictionary), but also each value will only be paired with a single key? I've been thinking of this as an "invertible" dictionary because you could swap the keys with the values without any collision...

Hash code in Dictionary<TKey, TValue>

I was playing around with Dictionary and stumbled across the below scenario public class MyObject { public string I { get; set; } public string J { get; set; } public string K { get; set; } public override int GetHashCode() { int hashCode = (I+J+K).GetHashCode(); Debugger.Log(9, "INFO", hashCode.ToSt...

Are there any freely available dictionaries?

I want to create dictionary for my iPhone application. For that I need a list of words with detailed meanings of the words in a database. Can anyone suggest me a good word list that is freely available? ...

.NET class for quickly find out Value based on Key and vice versa

Very often I use Dictionary<TKey, TValue> type to store ehh...dictionary type of values, e.g. Key = 1, Value ="Canada". But in many cases, values in the dictionary data is also unique, just like the Keys. And I find that for Dictionary<TKey, TValue> type, it is not very convenient to get key value based on value. My question is, which ...

Dictionary(string -> tuple) in .NET 3.5 ?

I was wondering if there's a way to create a dictionary using an anonymous type for its values. Something like { { "first", {1, true} }, { "second", {2, false} }, } I want to use this in .NET 3.5, so there's no vanilla implementation of Tuple<...> available. Any suggestions? ...

Problem with a instance and a Dictionary.

I try to work on a Force based 2D ship game. I have Forces, that a stored in a Dictionary, for 'Jets' on a ship. So I just have to say the name, the amplitude and let the engine do the acceleration/rotation. For that I have to rotate the force into the local coordinates of the ship, before I can apply it, but instead only rotating the n...

Can .NET Dictionary performance degrade with multithreaded access?

I have a situation where, in a multithreaded application, many different threads are accessing a Dictionary at the same time. It appears that this could be a bottleneck, but it's unclear - a plausible scenario is that multiple threads may be trying to retrieve the same value (do note, however, that the data structure is fixed - no thread...

Dictionary of Linq Expression

Hi guys, I'm trying to build a query using linq-to-sql and, in order to provide sorting capabilities, I wrote something like this: private Dictionary<string, Expression<Func<DataAccess.Auditing, object>>> OrderDict { get; set; } OrderDict = new Dictionary<string,Expression<Func<Augeos.GereonWeb.DataAccess.Auditing, object>>>(); Order...

Assigning to a dict

Forgive me if this has been asked before. I did not know how to search for it. I'm quite familiar with the following idiom: def foo(): return [1,2,3] [a,b,c] = foo() (d,e,f) = foo() wherein the values contained within the left hand side will be assigned based upon the values returned from the function on the right. I also know...

How do I store a list (or dict) of key terms from a regular expression? -Python

I am quite new at python and regex so please bear with me. I am trying to read in a file, match a particular name using a regex while ignoring the case, and store each time I find it. For example, if the file is composed of Bill bill biLl biLL, I need to store each variation in a dictionary or list. Current code: import re import sys im...

Bind a Dictionary<K,V> to a DropDownList

I was wondering why this doesn't work: Is it possible to declaratively bind to an Object's property. <asp:DropDownList id="ddl" runat="server" DataValueField="Key" DataTextField="Value.DisplayName" /> Code Behind var d = new Dictionary<int, MailAddress>(); d.Add(0,new MailAddress("[email protected]", "Mr. Foo"); d.Add(1...

IDictionary<obj, obj> to obj using emit

Hey We are about to do some reflector in my company. I need a FactoryClass that can convert an IDictionary to a obj, by doing a match on properties and dict keys. I found: http://stackoverflow.com/questions/1273589/dynamic-object-property-populator-without-reflection This code can do what I want, and I want to use this code, because...

Python: Compare dict with a static reference?

Hey, I have to check if a dictionary is the same as it was yesterday, if it has changed. In PHP I could have serialized an array and compared the resulting strings from yesterday and today. However, I don't know how to do it in Py. I've read a little about Pickle and maybe it could be done with md5 somehow? So basically I need a way t...

XML file to dictionary with nested dictionary.

I'm attempting to read the content of a XML file, using XmlTextReader in C#, that has the following structure: <root> <person id="0"> <a1>val</a1> <a2>val</a2> </person> <person id="1"> <a1>val</a1> <a2>val</a2> </person> </root> I'm looking to read the file into a nested dictionary: Dictionary<string, Diction...