dictionary

python dict.add_by_value(dict_2) ?

The problem: >>> a = dict(a=1,b=2 ) >>> b = dict( b=3,c=2) >>> c = ??? c = {'a': 1, 'b': 5, 'c': 2} So, the idea is two add to dictionaries by int/float values in the shortest form. Here's one solution that I've devised, but I don't like it, cause it's long: c = dict([(i,a.get(i,0) + b.get(i,0)) for i in set(a.keys()+b.keys()...

How to display a Dictionary in a ListBox

Hi I'm trying to display Key/Value Pairs from a Dictionary to a ListBox. Key Value A 10 B 20 C 30 I want to display them in a ListBox in following format A(10) B(20) C(30) Using following code I have been able to link Listbox.Datasource to Dictionary. myListBox.DataSource = new BindingSource(myDictionary, null); Its be...

Why doesn't .net provide us with the key when it raises a KeyNotFound Exception (and how can I get it?)

When you try to access a key which isn't in a Dictionary (for example), here's the stack trace you get : at System.ThrowHelper.ThrowKeyNotFoundException() at System.Collections.Generic.Dictionary`2.get_Item(TKey key) .... .... (my own code stack trace) Like most people probably do, I log this errors when they occur, ...

asp.net :is time complexity of searching an value by key in dictionary constant time or log2(n)?

i need a datastructure in dotnet where i can search an item in constant time.it means that datastructure should implement indexing internally.is dictionary usefull for this purpose or some other one? ...

hw search substring in a list of indexed strings?

i am implementing dictionary in which key is a string keyword.suppose i have following keys in dictionary. mat**hon** sat**hon** lat**hon** now if i serach single keyword suppose mathon it will search it in constant time.but if i am to search hon i want all of three words to be retreived in constant time or minimum time possible like...

dotnet:is there any way out to directly get reference of value collection in dictionary?

i want to sort dictionary based upon value of each dictioanry item.but if i use sorted dictionary search time complexity will increase from constant to log2(n).so i want to directly assign reference of value list in dictionary to a list.then i can sort this list and get results.i dont want to iterate to each element of dictionary to add ...

Can reading a list from a disk be better than loading a dictionary?

I am building an application where I am trying to allow users to submit a list of company and date pairs and find out whether or not there was a news event on that date. The news events are stored in a dictionary with a company identifier and a date as a key. newsDict('identifier','MM/DD/YYYY')=[list of news events for that date] ...

Fluent NHibernate HasMany in Component

Below is a class model and an Oracle schema that I would like to map it to using Fluent NHibernate. public enum EnumA { Type1, Type2, Type3 }; public class ClassB { public virtual string Property1 { get; set; } public virtual string Property2 { get; set; } } public class ClassA { public virtual int ID { get; set; } publ...

In Python how do I sort a list of dictionaries by a certain value of the dictionary + alphabetically?

Ok, here's what I'm trying to do... I know that itemgetter() sort could to alphabetical sort easy, but if I have something like this: [{'Name':'TOTAL', 'Rank':100}, {'Name':'Woo Company', 'Rank':15}, {'Name':'ABC Company', 'Rank':20}] And I want it sorted alphabetically (by Name) + include the condition that the one with Name:'...

Using a dictionary object in application scope in Classic ASP

Following up from my last question does anyone know how I can use a dictionary object in application scope in Classic ASP? You cannot use Scripting.Dictionary - if you try you will see something similar to the following: Application object error 'ASP 0197 : 80004005' Disallowed object use /xxx.asp, line 2. Cannot add object with apartme...

Extension method for Dictionary of Dictionaries

I'm trying to write an extension method to insert data into a dictionary of dictionaries defined as follows: items=Dictionary<long,Dictionary<int,SomeType>>() What I have so far is: public static void LeafDictionaryAdd<TKEY1,TKEY2,TVALUE>(this IDictionary<TKEY1,IDictionary<TKEY2,TVALUE>> dict,TKEY1 key1,TKEY2 key2,TVALUE value) ...

Does VBA have Dictionary structure?

Hi. Does VBA have dictionary structure? Like key<>value array? ...

Clearing a Collection of Collections - clear every item first, or just clear all at once?

Suppose I have a Collection of some kind that itself contains Collections; e.g., Dictionary(Of String, List(Of MyClass)). If I want to clear the Collection entirely, does it make any sense to clear every individual child collection before clearing the parent collection, like so: For Each ListDef As KeyValuePair(Of String, List(Of MyClas...

Store Dictionary<string,string> in application settings

I have a dictionary of strings that i want the user to be able to add/remove info from then store it for them so it they can access it the next time the program restarts I am unclear on how i can store a dictionary as a setting. I see that under system.collections.special there is a thing called a stringdictionary but ive read that SD a...

nested dictionary to nested repeater asp.net c#

Hi, I'm making an asp.page that will display hierarchical information about company assets. To grab the data I used a lambda expression: FASAssetInfoDataContext fasInfo = new FASAssetInfoDataContext(); var data = from g in fasInfo.Asset_Informations where g.Department.Substring(0, 3) == p ...

Formatting the output of a key from a dictionary

I have a dictionary which store a string as the key, and an integer as the value. In my output I would like to have the key displayed as a string without parenthesis or commas. How would I do this? for f_name,f_loc in dict_func.items(): print ('Function names:\n\n\t{0} -- {1} lines of code\n'.format(f_name, f_loc)) output: En...

Sorted Dictionary in C#

Is there any way I can iterate backwards (in reverse) through a SortedDictionary in c#? Or is there a way to define the SortedDictionary in descending order to begin with? ...

Dictionary, enum or other alternative for implementing a priority of a task in MVC?

Hi, I have got a task table in my database with a priority field containing an integer value from 1 to 4 as a test. I am using a LINQ to SQL dbml file so I have a task class and I want to be able to display the text value of the priority to the user in my view, as a value in a select list. I have added the below code to my task class: ...

What are the best data structure for mapping strings to values?

I'm interested in an answer that explain the best in each situation. In particular which is best for: few values lots of values many values with only few extensively used read only or nearly read only map write-a-lot map fast membership without retrieval memory footprint with large value others ...

Elegant way to go from list of objects to dictionary with two of the properties

i seem to write this code over and over again and wanted to see if there was a better way of doing it more generically. I start out with a list of Foo objects Foo[] foos = GenerateFoos(); I think want to create a dictionary where the key and value are both properties of Foo for example: Dictionary<string, string> fooDict = new Dict...