dictionary

Printing a particular subset of keys in a dictionary

I have a dictionary in Python where the keys are pathnames. For example: dict["/A"] = 0 dict["/A/B"] = 1 dict["/A/C"] = 1 dict["/X"] = 10 dict["/X/Y"] = 11 I was wondering, what's a good way to print all "subpaths" given any key. For example, given a function called "print_dict_path" that does this, something like print_dict_path("...

Is Dictionary<TKey, TValue> faster than LINQ on a List<T>?

I generally use List<T> for collections. But if I need a fast lookup on a collection, then e.g. in the following example I would use a Dictionary so I could look it up quickly by id: Dictionary<int, Customer> But since I can use LINQ to query the List<T> anyway, as below, is there any reason to go through the trouble of using a Dictio...

CGPDFDictionaryRef to something useful

A little bit of background: I'm appending an image to an already existing pdf file. I found out that there isn't a way to just add a page to it, you must recreate the whole pdf, then remove the old one then move the new one. (If that is wrong please tell me, and it will save me a lot of headaches.) I've accomplished that part, but I'm no...

How can I access the inbuilt (possibly predictive) dictionary of an iPhone/iPod

Hello, I'm writing an app that has it's own text input, overriding the usual keyboard. I want to include some kind of word completition. It would, for obvious reasons, be best, if I wouldn't have to supply my own dictionary, but instead could use the one already in place. Does anyone know how to access this dictionary? Is it even possi...

Is there a limit to entries in a Dictionary<> ?

I have about 3000 different files I need to organize, and retrieve at different times during the game. I created my own struct of variables. I was thinking about creating a "Dictionary " at the beginning of my application, and simply loading all my files before the game starts. I'm wondering about performance: will a dictionary with ...

How to iterate a dict of dynamic "depths" in python?

I have a dict data structure with various "depths". By "depths" I mean for example: When depth is 1, dict will be like: {'str_key1':int_value1, 'str_key2:int_value2} When depth is 2, dict will be like: {'str_key1': {'str_key1_1':int_value1_1, 'str_key1_2':int_value1_2}, 'str_key2': {'str_key2_1':int_value2_1, '...

How can I design a dict like sqlite class in python which can using different field as "key"?

Hi All, I have a such a data structure, "ID NAME BIRTH AGE SEX" ================================= 1 Joe 01011980 30 M 2 Rose 12111986 24 F 3 Tom 31121965 35 M 4 Joe 15091990 20 M I want to use python + sqlite to store and query data in a easy way. I am in trying to design a dict like...

Python lazy dictionary evaluation

Python evangelists will say the reason Python doesn't have a switch statement is because it has dictionaries. So... how can I use a dictionary to solve this problem here? The problem is that all values are being evaluated some and raising exceptions depending on the input. This is just a dumb example of a class that stores a number or ...

Validate words against an English dictionary in Rails?

Hi there, I've done some Google searching but couldn't find what I was looking for. I'm developing a scrabble-type word game in rails, and was wondering if there was a simple way to validate what the player inputs in the game is actually a word. They'd be typing the word out. Is validation against some sort of English language diction...

in a loop, only add to a dictionary or list or tuple if doesn't contains the key

I am looping in python and want to add a key to a dictionary only if it isn't already in the collection. How can I do this? mydic = {} for x in range(100): ?? ...

Use cases for the 'setdefault' dict method

The addition of collections.defaultdict in Python 2.5 greatly reduced the need for dict's setdefault method. This question is for our collective education: What is setdefault still useful for, today in Python 2.6/2.7? What popular use cases of setdefault were superseded with collections.defaultdict? ...

Implementing a hashtable for a question/answer group

What's the easiest way to implement a hashtable (or use a better way) to store a list of questions and their associated answers (1 possible answer per question)? Originally I had created an ArrayList to store the questions. I could have made a second ArrayList for the answers, but once I have a lot of questions, trying to match up quest...

Update App Engine model with dictionary

You can create a new model in App Engine using a dictionary: my_model = MyModel.get_or_insert(keyname, **kwargs) Is there a way to update a model using a dictionary instead of doing the following? my_model.firstprop = 'first' my_model.secondprop = 'second' ...

How to sum dict elements

In Python, I have list of dicts: dict1 = [{'a':2, 'b':3},{'a':3, 'b':4}] I want one final dict that will contain the sum of all dicts. I.e the result will be: {'a':5, 'b':7} N.B: every dict in the list will contain same number of key, value pairs. ...

Using dictionary in .NET

can i add one dictionary object to another dictionary. I mean i am having a check box list whose checked item are being added to a dictionary object by using foreach loop. in the same page i am having some more variable which are added to anther dictionary object now i have two dictionary object which i need to pass to a method but i wan...

How can I properly use multidimensional dictionaries in Cheetah for Python?

I have the following dictionary: {0: {'Shortname': 'cabling', 'Name': 'CAT5 Cabling', 'MSRP': '$45.00'}, 1: {'Shortname': 'antenna', 'Name': 'Radio Antenna', 'MSRP': '$35.00'}} And using Cheetah, the following section of template: #for $item in $items <tr> <td>$item.Name</td> <td>$item.MSRP</td> </tr> #end for When I run the code, ...

Why can't I create a dictionary<string, dictionary<string,string>>?

i want to create a dictionary like: Dictionary<string,<Dictionary<string, string>>> Why can't I? ...

Help with Linq and Dictionary's ContainsKey method

I'm writing a tool, and the first part of that tool is to collect all the header files in our public API. The problem is, two of the header files have duplicate file names (but they reside in different folders). This will cause a problem when creating a dictionary. Originally I wrote a foreach loop to collect FileInfo instances into a ...

Dictionary key value pair question

I have a dictionary pair i make an object of dictionary "paramList", now i have added key and value pair to that object, now i want to know if on the some other page i pass the object paramList in some method and on that page i know the key and i want to access it's corresponding value then how can i do that I have object like this D...

Passing and receiving routedictionary values in mvc2

I have a link in my action like this <%: Html.ActionLink("View Data","Index","MyItem", new {itemId=Model.itemId}, null)%> now in my newItem controller in its index action how do I retrieve this itemId, so far I have tried this public ActionResult Index() { RouteData rd = this.RouteData; var list = from...