dictionary

Merging Dictionaries in Python

I am intrigued by the following python expression: d3 = dict(d1, **d2) The task is to merge 2 dictionaries into a third one, and the above expression accomplishes the task just fine. I am interested in the ** operator and what exactly is it doing to the expression. I thought that ** was the power operator and haven't seen it used in t...

Sorting dictionary keys by values in a list?

I have a dictionary and a list. The values of the keys match those of the list, I'm just trying to find out how to sort the values in the dictionary by the values in the list. >>> l = [1, 2, 37, 32, 4, 3] >>> d = { 32: 'Megumi', 1: 'Ai', 2: 'Risa', 3: 'Eri', 4: 'Sayumi', 37: 'Mai' } I've tried using somethin...

Dictionary using generics

Hey guys, I am currently writing a resource manager for my game. This is basically a class that will handle all kinds of other objects of different types, and each object is referred to by name (a System.String). Now this is my current implementation, but since I am using a dictionary of objects I will still need to cast every object. I...

Bind dictionary to repeater

Hey, I have a dictionary object <string, string> and would like to bind it to a repeater. However, I'm not sure what to put in the aspx markup to actually display the key-value pair. There are no errors thrown and I can get it to work with a List. How do I get a dictionary to display in a repeater? Thanks Answer: I used this code in ...

.net dictionary vs other managed custom data structures, why is the .net dictionary so fast?

I am in the middle of developing a custom persistent Key Value type data structure, to compare against SqlLite and Berkley DB. Anyway before I wrote the implementation I wanted to find the best data structure to use for this purposes. I looked at the a couple: An open source redblack tree. Mono Dictionary implementation. I wanted th...

License of popular dictionary word lists (e.g. SOWPODS, TWL)? Copyright? Trademarks?

(I'm not sure if this off-topic. I found a lot of voted-up questions about software licenses and this is related. Plus, I'm sure many of us have had the situation that we need to use a dictionary in our code) I'm making a (maybe commercial) word game and need to use a good word dictionary for checking words. The most common dictionaries...

merging dictionaries in python

Hey everyone, Sorry for the very general title but I'll try to be as specific as possible. I am working on a text mining application. I have a large number of key value pairs of the form ((word, corpus) -> occurence_count) (everything is an integer) which I am storing in multiple python dictionaries (tuple->int). These values are sprea...

How is this Dictionary<TKey, TValue> exception possible?

Given the following stack trace: MESSAGE: Value cannot be null.Parameter name: key SOURCE: mscorlib TARGETSITE: Void ThrowArgumentNullException(System.ExceptionArgument) STACKTRACE:    at System.ThrowHelper.ThrowArgumentNullException(ExceptionArgument argument)    at System.Collections.Generic.Dictionary'2.FindEntry(TKey key)    at Syst...

C# Dictionary Composition

Let's say I have an arbitray list of A class A { string K {get;set;} string V {get;set;} } ... List<A> theList = ... Is there an easy way to compose a dictionary from theList? (something like the following) Dictionary<string, string> dict = magic(x => x.K, x => x.V, theList) I don't want to write the following code: var d = new D...

Python dictionary that maps strings to a set of strings?

I would like to be able to make a Python dictionary with strings as keys and sets of strings as the values. E.g.: { "crackers" : ["crunchy", "salty"] } It must be a set, not a list. However, when I try the following: word_dict = dict() word_dict["foo"] = set() word_dict["foo"] = word_dict["foo"].add("baz") ...

Separate word lists for nouns, verbs, adjectives, etc

Usually word lists are 1 file that contains everything, but are there separately downloadable noun list, verb list, adjective list, etc? I need them for English specifically. ...

Why dictionaries appear to be reversed?

Why dictionaries in python appears reversed? >>> a = {'one': '1', 'two': '2', 'three': '3', 'four': '4'} >>> a {'four': '4', 'three': '3', 'two': '2', 'one': '1'} How can I fix this? ...

How do I create a list or set object in a class in Python?

For my project, the role of the Lecturer (defined as a class) is to offer projects to students. Project itself is also a class. I have some global dictionaries, keyed by the unique numeric id's for lecturers and projects that map to objects. Thus for the "lecturers" dictionary (currently): lecturer[id] = Lecturer(lec_name, lec_id, ma...

Is nested dictionary in design ok?

My data is structured in a way that I ended up creating a nested dictionary in my design like: my_dict = {"a": {"b": {"c":"I am c"}}} my_dict["a"]["b"]["c"] Is it usual! or we have some other better alternatives (using objects!)? ...

How do quickly search through a .csv file in Python

I'm reading a 6 million entry .csv file with Python, and I want to be able to search through this file for a particular entry. Are there any tricks to search the entire file? Should you read the whole thing into a dictionary or should you perform a search every time? I tried loading it into a dictionary but that took ages so I'm current...

Dictionary<> Performance

Im using a Dictionary, i will have around a million entries and i will be regularly be adding, removing, editing, and polling.. im wondering what the up/down sides of all the entries will be, and if there is a more efficiant way. ...

Is there a way of checking for membership from the values of a dictionary? Once confirmed, can we do other things?

I understand that it's quite easy to check if a key is available in a dictionary, but what about certain values? So, what I have here is a dictionary of lists where the key references a set of, for consistency's sake, strings. It would look a bit like this: menu = {'breakfast':['soft-boiled eggs', 'hash brown', 'Earl Grey'], ...

Sampling keys due to their values

Hi guys, I have a dictionary(python) with key->value (str->int). I have to chose some key due to it's own value. Then bigger this value the key has less posibility to be chosen. For example if key1 has value 2 and key2->1 key1 the attitude should be 2:1. How can I do this? ...

count all items within a dictionary

Hi guys, my question is: I have a dictionary with one object for each character of the alphabet. Within those objects, there are all values for a specific character. Example: alphabetDictionary a apple alien b balloon ball I now want to count all entries within this dictionary: apple alien balloon ball -> 4 Usi...

python: dictionary dilemma: how to properly index objects based on an attribute

first, an example: given a bunch of Person objects with various attributes (name, ssn, phone, email address, credit card #, etc.) now imagine the following simple website: uses a person's email address as unique login name lets users edit their attributes (including their email address) if this website ha...