dictionary

How to use User dictionary?

Hi, Currently, I'm writing a soft keyboard app and it is using built-in dictionary. I want to enable user to add words to dictionary and get them while composing the text. I've found User dictionary in Settings->Language & keyboard. How to manage this dictionary through app? I want to add, delete and get words from User dictionary. ...

Most efficient Dictionary<K,V>.ToString() with formatting?

What's the most efficient way to convert a Dictionary to a formatted string. e.g.: My method: public string DictToString(Dictionary<string, string> items, string format){ format = String.IsNullOrEmpty(format) ? "{0}='{1}' " : format; string itemString = ""; foreach(var item in items){ itemString = itemString + St...

HTML Parsing, iterating over a Dictionary<>, no results returning when expected. C#

Working with HTML Agility Pack in C#. Running the following code on a site I know should return some values keeps coming up blank. Can anyone see what I'm doing wrong here? public Dictionary<string, string> linkMiner(string site) { Dictionary<string, string> links = new Dictionary<string, string>(); url = site; ...

Convert an array of objects to a dictionary of objects

i have an array of events: IEnumerable<CalendarEvent> events i want to convert this to a dictionary so i tried this: Dictionary<string, CalendarEvent> dict = events.ToDictionary(r => r.Date.ToString("MMM dd, yyyy")); the issue is that i have multiple events on a single date so i need a way to convert this to a Dictionary<string...

Multiple values for key in dictionary in Python

What I'm trying to do is get 3 values from a key into separate variables. Currently I'm doing it like this: for key in names: posX = names[key][0] posY = names[key][1] posZ = names[key][2] This doesn't seem very intuitive to me even though it works. I've also tried doing this: for key, value in names: location = value U...

How do I properly format plain text data for a simple Perl dictionary app?

I have a very simple dictionary application that does search and display. It's built with the Win32::GUI module. I put all the plain text data needed for the dictionary under the __DATA__ section. The script itself is very small but with everything under the __DATA__ section, its size reaches 30 MB. In order to share the work with my fri...

Can you convert C# dictionary to Javascript associative array using asp.net mvc Json()

I recently asked this question, but after some of the responses and some research, i wanted to change what i was actually asking. i have seen a number of blog posts about sending associative arrays from javascript to C# controller action but i want the opposite. I want to return json to a client as a dictionary (from my research the ja...

Why to copy a dictonairy from WSGI environment?

In the following example from wsgi.org is cur_named copied: def __call__(self, environ, start_response): script_name = environ.get('SCRIPT_NAME', '') path_info = environ.get('PATH_INFO', '') for regex, application in self.patterns: match = regex.match(path_info) if not match: continue extr...

Sql Alchemy > TypeError: 'instancemethod' object does not support item assignment

Here's what I've got: from sqlalchemy import * from sqlalchemy.orm import * from web.models.card import * connectionString = "postgresql://www:www@localhost/prod" databaseEngine = create_engine(connectionString) sessionFactory = sessionmaker(autoflush = True, autocommit = False, bind = databaseEngine) session = sessionFactory() CardsCo...

minimum value in dictionary using linq

Hi I have a dictionary of type Dictionary<DateTime,double> dictionary How can I retrive a minimum value and key coresponding to this value from this dictionary using linq ? ...

Django / Python, using iteritems() to update database gives strange error: "dictionary update sequence element #0 has length 4; 2 is required"

I'm trying to do a Django database save from a form where I don't have to manually specify the fieldnames (as I do in the 2nd code block), the way I am trying to do this is as below (1st code block) as I got the tip from another S.O. post. However, when I try this I get the error "dictionary update sequence element #0 has length 4; 2 is ...

Building a generic collection class.

Hi all, I am building the following class to manage a dictionary. public class EnumDictionary<TKey, TValue> { private Dictionary<TKey, TValue> _Dict; public EnumDictionary(Dictionary<TKey, TValue> Dict) { this._Dict = Dict; } public TKey GetValue(TValue value) { ...

ui:msg with Dictionary in GWT

Hi Is it possible to use ui:msg with a Dictionary or a custom HashMap in GWT? If so how? Thanks A ...

Global dictionary vs. GCHandle

Hey, I am required to pass some sort of identifier to unmanaged code which then processes a request and calls back into my managed code once it has done some processing. I was wondering whether it would be better to create a GCHandle and pass it to the unmanaged code to then recover the object once the unmanaged code passes the GCHandl...

How does Forth implement the dictionary? (controversy)

I am studying Forth for a personal project I have on my mind. It looks to be a really cool and simple language to implement in a small virtual machine. I am especially impressed by the possibilities of the use of vocabularies on it. On the other hand, I think the way the dictionary works is overly complex for a language that is overall ...

What would be a sensible way to implement a Trie in .NET?

I get the concept behind a trie. But I get a little confused when it comes to implementation. The most obvious way I could think to structure a Trie type would be to have a Trie maintain an internal Dictionary<char, Trie>. I have in fact written one this way, and it works, but... this seems like overkill. My impression is that a trie sh...

Are order of keys() and values() in python dictionary guaranteed to be the same?

Does native built-in python dict guarantee that the keys() and values() lists are ordered in the same way? d = {'A':1, 'B':2, 'C':3, 'D':4 } # or any other content otherd = dict(zip(d.keys(), d.values())) Do I always have d == otherd ? Either it's true or false, I'm interested in any reference pointer on the subject. PS: I understan...

Python: Testing if a value is present in a defaultdict list

I want test whether a string is present within any of the list values in a defaultdict. For instance: from collections import defaultdict animals = defaultdict(list) animals['farm']=['cow', 'pig', 'chicken'] animals['house']=['cat', 'rat'] I want to know if 'cow' occurs in any of the lists within animals. 'cow' in animals.valu...

going through a dictionary and printing its values in sequence

def display_hand(hand): for letter in hand.keys(): for j in range(hand[letter]): print letter, Will return something like: b e h q u w x. This is the desired output. How can I modify this code to get the output only when the funtion has finished its loops? Something like below code causes me problems as I can...

Truth table as the keys for a dictionary

I have six boolean flags that are independent of each other so there are 64 possible combinations. These flags should determine the value of some string. This string can have seven different values. I think implementing this as a large if-statement is a bad idea so I thought of creating a truth table where each combination determines a s...