dictionary

Cocoa: Dictionary with enum keys?

I need to create a dictionary/hashmap where the Keys are enums Values are some subclass of NSObject NSDictionary won't work here (enums don't conform to NSCopying). I could perhaps use a CFDictionaryRef here, but I'd like to know if is there any other way to achieve this. ...

Seed data for sentiment analysis

I'm playing around with sentiment analysis, and I'm looking for some seed data. Is there a free dictionary around? It can be really simple: 3 sets of texts/sentences, for "positive", "negative", "neutral". It doesn't have to be huge. Eventually I'll probably generate my own seed data for my specific use case, but it would be great to...

F#: How do you declare the values of a dictionary entry as mutable?

The Google yields plenty of example of adding and deleting entries in an F# dictionary (or other collection). But I don't see examples to the equivalent of myDict["Key"] = MyValue; I've tried myDict.["Key"] <- MyValue I have also attempted to declare the Dictionary as Dictionary<string, mutable string> as well several variants o...

how to use Dictionary or Hashtable in Javascript?

Possible Duplicate: Can anyone recommend a good Hashtable implementation in Javascript? Hello everyone, I want to calculate/store some statistics information using JavaScript, the equivalent code in C# is below (features I need are -- key-value pair, string/int key value pair, manipulate values by keys, etc.), any ideas how to ...

Dictionary with classes?

In Python is it possible to instantiate a class through a dictionary? shapes = {'1':Square(), '2':Circle(), '3':Triangle()} x = shapes[raw_input()] I want to let the user pick from a menu and not code huge if else statements on the input. For example if the user entered 2, x would then be a new instance of Circle. Is this possible?...

Multiple synonym dictionary matches in PostgreSQL full text searching

I am trying to do full text searching in PostgreSQL 8.3. It worked splendidly, so I added in synonym matching (e.g. 'bob' == 'robert') using a synonym dictionary. That works great too. But I've noticed that it apparently only allows a word to have one synonym. That is, 'al' cannot be 'albert' and 'allen'. Is this correct? Is there any ...

Basic Python dictionary question

I have a dictionary with one key and two values and I want to set each value to a separate variable. d= {'key' : ('value1, value2'), 'key2' : ('value3, value4'), 'key3' : ('value5, value6')} I tried d[key][0] in the hope it would return "value1" but instead it return "v" Any suggestions? ...

Filtering dictionaries and creating sub-dictionaries based on keys/values in Python?

Ok, I'm stuck, need some help from here on... If I've got a main dictionary like this: data = [ {"key1": "value1", "key2": "value2", "key1": "value3"}, {"key1": "value4", "key2": "value5", "key1": "value6"}, {"key1": "value1", "key2": "value8", "key1": "value9"} ] Now, I need to go through that dictionary already to format some o...

Python: sorting a dictionary of lists

Still learning python (finally!) and can't quite wrap my head around this one yet. What I want to do is sort a dictionary of lists by value using the third item in the list. It's easy enough sorting a dictionary by value when the value is just a single number or string, but this list thing has me baffled. Example: myDict = { 'item1' ...

need to put a nested Dict into a text file

I have a nested dict like this d={ time1 : column1 : {data1,data2,data3} column2 : {data1,data2,data3} column3 : {data1,data2,data3} #So on. time2 : {column1: } #Same as Above } data1,data2,data3 represent the type of data and not the data itself I need to put this dict into a file like ...

Problem with hash function: hash(1) == hash(1.0)

I have an instance of dict with ints, floats, strings as keys, but the problem is when there are a as int and b as float, and float(a) == b, then their hash values are the same, and thats what I do NOT want to get because I need unique hash vales for this cases in order to get corresponding values. Example: d = {1:'1', 1.0:'1.0', '1':1...

With Python, can I keep a persistent dictionary and modify it?

So, I want to store a dictionary in a persistent file. Is there a way to use regular dictionary methods to add, print, or delete entries from the dictionary in that file? It seems that I would be able to use cPickle to store the dictionary and load it, but I'm not sure where to take it from there. ...

C# String replace with dictionary

I have a string on which I need to do some replacements. I have a Dictionary<string, string> where I have search-replace pairs defined. I have created following extension methods to perform this operation: public static string Replace(this string str, Dictionary<string, string> dict) { StringBuilder sb = new StringBuilder(str); ...

Concatenating Dictionaries

I have three lists, the first is a list of names, the second is a list of dictionaries, and the third is a list of data. Each position in a list corresponds with the same positions in the other lists. List_1[0] has corresponding data in List_2[0] and List_3[0], etc. I would like to turn these three lists into a dictionary inside a dictio...

PYTHON: Converting list of tuples into a dictionary

Hi, I'm looking for a way to convert list of tuples which looks like this: [(1,4),(2,4),(3,4),(4,15),(5,15),(6,23),(7,23),(8,23),(9,15),(10,23),(11,15),(12,15)] into a dictionary, where key:value pair looks like this: {4:[1,2,3] ,15:[4,5,9,11,12], 23:[6,7,8,10]} Second element from a tuple becomes a dictionary key. First tuple ele...

Python: remove dictionary from list

If I have a list of dictionaries, say: [{'id': 1, 'name': 'paul'}, {'id': 2, 'name': 'john'}] and I would like to remove the dictionary with id of 2 (or name john), what is the most efficient way to go about this programmatically (that is to say, I don't know the index of the entry in the list so it can't simply be popped). ...

CircularBuffer IDictionary in C#?

I need a CircularBuffer IDictionary. Can anyone point me to a good open source implementation. So a IDictionary that has a maximum capacity, say configured to 100 items, which when item 101 is added the original first item is popped/removed from the dictionary thus ensuring the item count never exceeds 100. Thanks ...

How to filter a dictionary by value?

Hello, Newbie question here, so please bear with me. Let's say I have a dictionary looking like this: a = {"2323232838": ("first/dir", "hello.txt"), "2323221383": ("second/dir", "foo.txt"), "3434221": ("first/dir", "hello.txt"), "32232334": ("first/dir", "hello.txt"), "324234324": ("third/dir", "dog.txt")} I want...

Is this an ASP.NET MVC 2 Preview 1 bug, and what's the work-around?

I'm using this code in ASP.NET MVC 2 preview 1: public ActionResult List(long id, [DefaultValue(0)] long? commentId) { var model = UserComment.ForRefId(id); PageTitle = string.Format("Comments for '{0}'", SetCommentThread(id).Subject); ViewData[MvcApplication.SAnchor] = ...

how to update the value stored in Dictionary in C#?

Hi, I work on .net 2.0 and would like to do the following. I want to update the value in the Dictionary for a specific key. I will be putting it in a for loop so that the value gets updated for all the keys passed in. Any idea? ...