dictionary

Is there any API to integrate with English dictionary in PHP ?

Is this possible to Integrate with any English Dictionary, so that every word entered in my text-box should be cross checked from the Dictionary and return me true/false. ...

Best way to use a List<T> in a Key/Value collection?

Hi, What's the best way to keep a collection-object (List in example) in a Key/Value situation, where the key is a ID and the value is a collection of a type T? Is this the only option or is there a better solution/another collection for this in .NET 3.5? var x = new Dictionary<int, List<type>>(); ...

Why can't I .add a Dictionary(Key, Value) in a foreach?

If I want to loop over a Dictionary(Key, Value)... why cant I add a new key-value pair in the loop? Dictionary<string, string> persons = new Dictionary<string, string>(); persons.Add("roger", "12"); persons.Add("mary", "13"); foreach (KeyValuePair<string,string> person in persons) { Console.WriteLine("Name: " + person.Key + ", Age: "...

How do I identify language of a text document in Java?

Is there an existing Java library that could tell me whether a String contains English language text or not (e.g. I need to be able to distinguish French or Italian text -- the function needs to return false for French and Italian, and true for English)? ...

(c#) using dictionary as a key in other dictionary

Hello :) Just as in title. I would like to use dict as a key in another dict. Something similar to python. I tried this but it gives me errors. Dictionary<Dictionary<string, string>, int> dict = new Dictionary<Dictionary<string, string>, int>(); Dictionary<string, string> dict2 = new Dictionary<string, string>(); dict2["abc"] = "def...

Comparing dictionaries in Python

Given two dictionaries, d1 and d2, and an integer l, I want to find all keys k in d1 such that either d2[k]<l or k not in l. I want to output the keys and the corresponding values in d2, except if d2 does not contain the key, I want to print 0. For instance, if d1 is a: 1 b: 1 c: 1 d: 1 and d2 is a: 90 b: 89 x: 45 d: 90 and l is 9...

What internal dictionary does FxCop use?

FxCop must base itself on some internal dictionary. Does it use Word dictionaries if they are installed? When running FxCop on my build server it doesn't find any spelling errors, but on my developer machine it does. I am aware of the custom dictionary, but it is not the issue in this case. On the build server it accepts any word. ...

Dictionary like implementation in C/C++ (Update info)

Does anyone have information or example of how to mount the equivalent of a Dictionary (VB6) in C or C++ ? This implementation is used to be passed as a parameter called DLL VB6. My intention is to create a Dictionary in C (win32 using VARIANT/ARRAYs, etc) and pass it to call a VB. So I have to learn how to create this data structure. ...

C# concurrency, locking and dictionary objects

I have a bunch of DB entities that are loaded into DB objects. The same DB entity may be loaded into more than DB object. Periodically a DB entity will require special processing. This processing must be performed by one thread at a time. Locking is in order here. EDIT: Important note: the process calls a slow web service. This ...

What's the most efficient way to access sibling dictionary value in a Python dict?

In Python, I've got a list if dictionaries that looks like this: matchings = [ {'id': 'someid1', 'domain': 'somedomain1.com'}, {'id': 'someid2', 'domain': 'somedomain2.com'}, {'id': 'someid3', 'domain': 'somedomain3.com'} ] and, I have a variable: the_id = 'someid3' What's the most efficient way to retrieve the domain v...

How do I convert from a Dictionary to a SortedDictionary using LINQ in C#?

I have a Dictionary<string, double> and I want to convert it to a SortedDictionary<double, string>. How do I do this using LINQ extension methods in C# 3.0? EDIT: Generic angle brackets not in original question when Marc and Jared answered. ...

Is there a fast way to generate a dict of the alphabet in Python?

I want to generate a dict with the letters of the alphabet as the keys, something like letter_count = {'a': 0, 'b': 0, 'c': 0} what would be a fast way of generating that dict, rather than me having to type it in? Thanks for your help. EDIT Thanks everyone for your solutions :) nosklo's solution is probably the shortest Also, tha...

Strange behaviour of .NET binary serialization on Dictionary<Key, Value>

I encountered a, at least to my expectations, strange behavior in the binary serialization of .NET. All items of a Dictionary that are loaded are added to their parent AFTER the OnDeserialization callback. In contrast List does the other way. This can be really annoying in real world repository code, for example when you need to add som...

Best way to remove multiple items matching a predicate from a c# Dictionary ?

I need to remove multiple items from a Dictionary. A simple way to do that is as follows : List<string> keystoremove= new List<string>(); foreach (KeyValuePair<string,object> k in MyCollection) if (k.Value.Member==foo) keystoremove.Add(k.Key); foreach (string s in keystoremove) MyCollection.Remove(s); The re...

Python: how to check if a given index in a dict exists yet?

Given a dict, how can I find out if a given index in that dict has already been set to a non-None value? I.e., I want to do this: my_dict = {} if (my_dict[some_value] != None): my_dict[some_value] = 1 else: my_dict[some_value] += 1 I.e., I want to increment the value if there's already one there, or set it to 1 otherwise. ...

No more "If / Then"; Dictionary Use?

I am writing a piece of code that to work would require an extensive amount of if/then statements. In order to eliminate the need for writing line upon line of if/then statements can I use a dictionary or a list? If so can someone direct me to a good web resource or show an instance where they have done it before? Edit Clarification: ...

Python reverse / inverse a mapping

Given a dictionary likeso: map = { 'a': 1, 'b':2 } How can one invert this map to get: inv_map = { 1: 'a', 2: 'b' } ...

How do I add a Python-style Get() method which takes a default value to my C# dictionaries?

I'd like to be able to specify a default value to return if the key I specify can't be found in the dictionary. e.g. int default = 5; string key = "MyKey"; int foo = myDictionary.GetValue(key, default); if key is in myDictionary foo should hold the value from the dictionary, otherwise it will hold 5. ...

C# Dictionary Application: Applying Values through the selection of keys

I have a dictionary that I am using to define the ratings of copper cable. I want to use these values to calculate how many cables it will take to meet a certain connections rating. The size of the connection, the cable type, and system type are selected by two ComboBoxs named cb_amperage, cb_cable_size and, cb_system_type. The answer f...

Converting Value Type of a Dictionary in VB.net

Public Class A Public Class B : Inherits A Dim DictA As Dictionary(Of Integer, A) Dim DictB As New Dictionary(Of Integer, B) DictA = DictB This doesn't work, as the type can't be converted. Is this somehow possible? ...