dictionary

Objective-C dictionary inserting a BOOL

OK, I'm a little confused. It's probably just a triviality. I've got a function which looks something like this: - (void)getNumbersForNews:(BOOL)news andMails:(BOOL)mails { NSMutableDictionary *parameters = [[NSMutableDictionary alloc] init]; [parameters setValue:news forKey:@"getNews"]; [parameters setValue:mails forKey:@"getMails"]...

Saving huge bigram dictionary to file using pickle

a friend of mine wrote this little progam. the textFile is 1.2GB in size (7 years worth of newspapers). He successfully manages to create the dictionary but he cannot write it to a file using pickle(program hangs). import sys import string import cPickle as pickle biGramDict = {} textFile = open(str(sys.argv[1]), 'r') biGramDictFile =...

Is using shared Dictionaries a good solution to the lack of "extension properties"?

Suppose I have some extension methods but also need to extend the object's state. Seeing as there is no support for extension properties in C#, would using shared static Dictionary be a good solution? For example something like this: class Foo { // 3rd party class } static class Helper { private static Dictionary<Foo, Gui...

Python - uniquifying(!) dictionary keys

I have data coming in from a machine (via pexpect) and I parse it using regexes into a dictionary like this for line in stream: if '/' in line: # some matching etc which results in getting the # machine name, an interface and the data for that interface key=str(hostname)+":"+r.groups()[0][0:2]+r.groups()[2]...

Filtering out values from a C# Generic Dictionary

I have a C# dictionary, Dictionary<Guid, MyObject> that I need to be filtered based on a property of MyObject. For example, I want to remove all records from the dictionary where MyObject.BooleanProperty = false. What is the best way of acheiving this? ...

Merging Dictionary containing a List in C#

This is kind-of related to this question, on how to merge two dictionaries in C#. An elegant Linq solution is presented, which is cool. However, that question relates to Dictionary<Object1, Object2>, whereas I have a dictionary where the value is a List<Object2>. I am looking for a solution for merging a Dictionary<Object1, List<Object...

C# inherit from Dictionary, iterate over KeyValuePairs

I have a class that inherits from Dictionary<string, string>. Within an instance method, I want to iterate over all KeyValuePair<string, string>'s. I've tried doing the following: foreach (KeyValuePair<string, string> pair in base) But this fails with the following error: Use of keyword 'base' is not valid in this context How ...

Dictionary with no 'payload' value in .Net

Occassionally I need to check for duplicate IDs in a set of values and generally I use a Dictionary for this - using just the keys and leaving values empty. Note that this is tight and highly optimized code so please no cries of 'premature optimization'! Assuming scenarios where CPU and RAM are being squeezed to the limit I was wanting...

What happens to C# Dictionary<int, int> lookup if the key does not exist?

I tried checking for null but the compiler warns that this condition will never occur. What should I be looking for? ...

Resources for programs teaching natural languages

What API's and data sets are available for use in programs to teach natural languages e.g. to aid in learning to read/write/listen/speak a 2nd language? These could be web or traditional API's to dictionaries, translation services, associations of words / concepts to images, sounds e.g. spoken words or phrases, movies, or sets of flashca...

A dictionary object that uses ranges of values for keys

Hey all, I have need of a sort of specialized dictionary. My use case is this: The user wants to specify ranges of values (the range could be a single point as well) and assign a value to a particular range. We then want to perform a lookup using a single value as a key. If this single value occurs within one of the ranges then we w...

how to convert a xml string to a dictionary in python

Hello guys, I've a program that reads a xml document from a socket, so I've the xml document stored in a string which I would like to convert directly to a python dictionary, the same way it is done in django's simplejson library. Take as an example: str ="<?xml version="1.0" ?><person><name>john</name><age>20</age></person" dic_xml = ...

IDictionary<TKey, TValue> in .NET 4 not covariant

The IDictionary<TKey, TValue> in .NET 4 / Silverlight 4 does not support covariance, i.e. I can't do a IDictionary<string, object> myDict = new Dictionary<string, string>(); analog to what I can do with IEnumerable<T>s now. Probably boils down to the KeyValuePair<TKey, TValue> not being covariant either. I feel that covariance should...

.net Hashtable insert failed. Load factor too high.

Hello, I'm getting this error: Hashtable insert failed. Load factor too high. Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. Exception Details: System.InvalidOperationException: Hashtabl...

C# Binary Trees and Dictionaries

I'm struggling with the concept of when to use binary search trees and when to use dictionaries. In my application I did a little experiment which used the C5 library TreeDictionary (which I believe is a red-black binary search tree), and the C# dictionary. The dictionary was always faster at add/find operations and also always used les...

gen_server with a dict vs mnesia table vs ets

Hi, I'm building an erlang server. Users sends http requests to the server to update their status. The http request process on the server saves the user status message in memory. Every minute the server sends all messages to a remote server and clear the memory. If a user update his status several times in a minute, the last message ove...

English Lexicon for Search Query Correction

I'm building a spelling corrector for search engine queries by implementing the method described in "Spelling correction as an iterative process that exploits the collective knowledge of web users". The high-level approach is as follows: for a given query, come up with possible correction candidates (words in the query log within a c...

c# : how to easily display a Dictionary<string, int> ?

I have a dictionary that I want to show in a form. What's the easiest way to do this ? Preferrably I'd like to show a control where I can sort using the int-value. I've tried a DataGridView but nothing shows up, I must be doing something wrong... Code: mDataGridView.DataSource = mWordCount; /*Where mWordCount is the Dictionary<string...

WCF service returning an array of dictionary<string, object>.

Hi I've been trying to use a silverlight client to call an asp.net wcf service that would return a Dictionary. That worked fine when the values in the dictionary were simples types like int, string or Guid. However, I now have a scenario where I need one of the values to be an array of dictionary ! It all compiles fine and the signature...

Automatically creating a collection in the Dictionary<Key, Collection<Value>>

Lot of times I have to create a Dictionary<KeyType, List<ValueType>> Before I can start using the dictionary I have to first verify that List has been created for that key. //Can i remove these two lines? if(!dict.ContainsKey(key)) dict[key]= new List<ValueType>; //now use the key dict[key].Add(value); I know its only "2 lines"...