dictionary

Dictionary returning a default value if the key does not exist

I find myself using the current pattern quite often in my code nowadays var dictionary = new Dictionary<type, IList<othertype>>(); // Add stuff to dictionary var somethingElse = dictionary.ContainsKey(key) ? dictionary[key] : new List<othertype>(); // Do work with the somethingelse variable Or sometimes var dictionary = new Dictiona...

Accessing a dictionary value by custom object value in Python?

So I have a square that's made up of a series of points. At every point there is a corresponding value. What I want to do is build a dictionary like this: class Point: def __init__(self, x, y): self._x = x self._y = y square = {} for x in range(0, 5): for y in range(0, 5): point = Point(x,y...

Quickest way to dump Python dictionary (dict) object to a MySQL table?

I have a dict object. I dumped the data using this: for alldata in data: # print all data to screen print data[alldata] Each field had brackets [] and 'None' values for NULLS and date.datetime for date values. How do I dump this dict to MySQL table? Thank you! print data displays something like this : {'1': ['1', 'K', abc, 'xyz...

.NET SortedDictionary But Sorted By Values

I need a data structure that acts like a SortedDictionary<int, double> but is sorted based on the values rather than the keys. I need it to take about 1-2 microseconds to add and remove items when we have about 3000 items in the dictionary. My first thought was simply to switch the keys and values in my code. This very nearly works. ...

How do I insert data from a Python dictionary to MySQL?

I manipulated some data from MySQL and the resulting dictionary "data" (print data) displays something like this : {'1': ['1', 'K', abc, 'xyz', None, None, None, datetime.date(2009, 6, 18)], '2': ['2', 'K', efg, 'xyz', None, None, None, None], '3': ['3', 'K', ijk, 'xyz', None, None, None, datetime.date(2010, 2, 5, 16, 31, 2)]} How d...

Keywords dictionary

I developed a web site to search a database of videos indexed by keywords. There are several keywords that are repeated like "kid" and "kids" or "children" I'd like that when users search for a keyword they will find also videos with similar keywords and keywords translation (ex. "kid" > "kinder"). I was thinking about using an externa...

Getting Dictionary<string,string> from List<Control>

I want a dictionary containing the names and text of all controls. Is it possible with predefined framework methods/LINQ/colection initializers or do I have to make a loop and add all entries by myself? This gives me an error message: List<Control> controls; // .. initialize list .. controls.ToDictionary((Control child,string k)=>new K...

.NET values lookup

Hi, I have a feeling of missing something obvious. UDP receiver application. It holds a collection of valid UDP sender IPs - only guys with IP on that list will be considered. Since that list must be looked at on every packet and UDPs are so volatile, that operation must be maximum fast. Good choice is Dictionary but it is a key-value ...

python: sorting

hi im doing a loop so i could get dict of data, but since its a dict it's sorting alphabetical and not as i push it trought the loop ... is it possible to somehow turn off alphabetical sorting? here is how do i do that data = {} for item in container: data[item] = {} ... for key, val in item_container.iteritems(): ... d...

Performance comparison of Dictionaries

I'm interested in performance values (big-O analysis) of Lookup and Insert operation for .Net Dictionaries (generic or not): HashTable, SortedList, StringDictionary, ListDictionary, HybridDictionary, NameValueCollection, SortedList < T, U >, Dictionary < T,U > Link to a web page with the answer works for me too. ...

What's the simplest way to get the highest and lowest keys from a dictionary?

self.mood_scale = { '-30':"Panic", '-20':'Fear', '-10':'Concern', '0':'Normal', '10':'Satisfaction', '20':'Happiness', '30':'Euphoria'} I need to set two variables: max_mood and min_mood, so I can put some limits on a ticker. What's the easiest way to get the lowest and the highest keys? ...

How would I merged nested dictionaries in a list in python?

for example if i had the result [{'Germany': {"Luge - Men's Singles": 'Gold'}}, {'Germany': {"Luge - Men's Singles": 'Silver'}}, {'Italy': {"Luge - Men's Singles": 'Bronze'}}] [{'Germany': {"Luge - Women's Singles": 'Gold'}}, {'Austria': {"Luge - Women's Singles": 'Silver'}}, {'Germany': {"Luge - Women's Singles": 'Bronze'}}] [{'Austr...

Find size of dictionary object in VBA

What is the simplest way in VBA to determine the size (i.e., number of keys) in a dictionary object? ...

delta-dictionary/dictionary with revision awareness in python?

I am looking to create a dictionary with 'roll-back' capabilities in python. The dictionary would start with a revision number of 0, and the revision would be bumped up only by explicit method call. I do not need to delete keys, only add and update key,value pairs, and then roll back. I will never need to 'roll forward', that is, when ro...

How to delete a Dictionary row that is a Double by using an Int?

Hi, I have a Dictionary object that is formed using a double as its key values. It looks like this: Dictionary<double, ClassName> VariableName = new Dictionary<double, ClassName>(); For my project I have to have the key as the double as I require values like 1.1,1.2,2.1,2.2,etc in my system. Everything in my system works great excep...

Does sending a dictionary through a multiprocessing.queue mutate it somehow?

I have a setup where I send a dictionary through a multiprocessing.queue and do some stuff with it. I was getting an odd "dictionary size changed while iterating over it" error when I wasn't changing anything in the dictionary. Here's the traceback, although it's not terribly helpful: Traceback (most recent call last): File "/usr/li...

Is there a way to use a dictionary or xml in the Application Settings?

I have to store a complex type in the application settings. I thought that storing it as XML would work best. The problem is I don't know how store XML. I prefer to store it as a managed XML rather than using just a string of raw XML having to parse it on each access. I managed to set the Type column of the setting to XDocument, but I w...

iPhone: How to write plist array of dictionary object

Hello, I'm a young Italian developer for the iPhone. I have a plist file (named "Frase") with this structure: Root Array - Item 0 Dictionary Frase String Preferito Bool - Item 1 Dictionary Frase String Preferito Bool - Item 2 Dictionary Frase String ...

IXmlSerializable Dictionary problem

I was trying to create a generic Dictionary that implements IXmlSerializable (credit to Charles Feduke). Here is my trial: Sub Main() Dim z As New SerializableDictionary(Of String, String) z.Add("asdf", "asd") Console.WriteLine(z.Serialize) End Sub Result: <?xml version="1.0" encoding="utf-16"?><Entry key="asdf" value="a...

English dictionary as txt or xml file with support of synonyms

Can someone point me to where I can download English dictionary as a txt or xml file. I am building a simple app for myself and looking for something what I could start using immediately without learning complex API. Support for synonyms would be great, that is it should be easier to retrieve all the synonyms for particular word. It wo...