dictionary

appending successfully to a python list

This may seem like the worlds simplest python question... But I'm going to give it a go of explaining it. Basically I have to loop through pages of json results from a query. the standard result is this {'result': [{result 1}, {result 2}], 'next_page': '2'} I need the loop to continue to loop, appending the list in the result key to...

Fastest way to insert a word at the correct position in a dictionary

Currently, I'm simply inserting the word into the dictionary (ArrayList<String>) and then sorting the dictionary like so: dictionary.add(newWord); Collections.sort(dictionary, new Comparator<String>(){ public int compare(String s1, String s2) { return s1.compareToIgnoreCase(s2); } }); I'm trying to determine wh...

Algorithm wanted: Find all words of a dictionary that are similar to words in a free text

We have a list of about 150,000 words, and when the user enters a free text, the system should present a list of words from the dictionary, that are very close to words in the free text. For instance, the user enters: "I would like to buy legoe toys in Walmart". If the dictionary contains "Lego", "Car" and "Walmart", the system should p...

Finding the highest key

I'm just confused about why my code would not work, here's the question and the code I have so far (the test run says my answer is wrong). Given the dictionary d, find the largest key in the dictionary and associate the corresponding value with the variable val_of_max. For example, given the dictionary {5:3, 4:1, 12:2}, 2 would be asso...

Optimizing word count

(This is rather hypothetical in nature as of right now, so I don't have too many details to offer.) I have a flat file of random (English) words, one on each line. I need to write an efficient program to count the number of occurrences of each word. The file is big (perhaps about 1GB), but I have plenty of RAM for everything. They're...

How to insert values into VB.NET Dictionary on instantiation?

Is there a way that I can insert values into a VB.NET Dictionary when I create it? I can, but don't want to, do dict.Add(int, "string") for each item. Basically, I want to do "How to insert values into C# Dictionary on instantiation?" with VB.NET. var dictionary = new Dictionary<int, string> { {0, "string"}, {1, "...

"Peeking Ahead" while looping through Dictionary Items

This seems like it should be something very easy to do, but every time I approach this issue, I end up w/ solutions that feel "less than elegant" Here is my basic question: If I am looping through a dictionary that I have ordered in a particular way, within any given point in the loop how can I "peek" or get reference to a dictionary ...

Dictionary Operations... Index / Iterate / Validate

I'd like to: Check a key / value at position i Check to see if key / value contains a string delete / store in another variable either the key / value The equivelant of this Java code: //Some list... ArrayList<String> example; ... //Index into data structure example.get(i); //Check for some string... if (example.get(i).contains("som...

Converting Python Dictionary to List

I'm trying to convert a Python dictionary into a Python list, in order to perform some calculations. #My dictionary dict = {} dict['Capital']="London" dict['Food']="Fish&Chips" dict['2012']="Olympics" #lists temp = [] dictList = [] #My attempt: for key, value in dict.iteritems(): aKey = key aValue = value temp.append(aKey)...

Simple list of sub category

I have a plist with categories : <array> <dict> <key>part</key> <string>up</string> <key>house</key> <array> <dict> <key>name</key> <string>name1</string> <key>theme</key> <string>theme1</string> <key>image</key> <string>image1.png</string> </dict> </array> </dict> <dict> <key>part</key> <string>down</string...

Sorting Lists of List of Dictionaries

I've just read in a file that is something like: name: john, jane car: db9, m5 food: pizza, lasagne Each of these rows (names, car, food) are in order of who owns what. Therefore John owns the car 'DB9' and his favourite food is 'Pizza'. Likewise with Jane, her car is an 'M5' and her favourite food is 'Lasagne'. I effectively have: ...

Deleting from dict if found in new list in Python

Say I have a dictionary with whatever number of values. And then I create a list. If any of the values of the list are found in the dictionary, regardless of whether or not it is a key or an index how do I delete the full value? E.g: dictionary = {1:3,4:5} list = [1] ... dictionary = {4:5} How do I do this without creating a new ...

How to Deserialise Xml into a Dictionary<int,string> object?

Is it possible to Deserialize the following piece of XML into a Dictionary<int,string> object? XML: <Config> <DatabaseConnections> <Connection Name="Source Connection" Value="ConnectionStringValue" /> <Connection Name="Target Connection" Value="ConnectionStringValue" /> <DatabaseConnections> <Config> I have a class which ...

Is there any benefit to returning a hash constructed with dict rather than just using the curly braces syntax?

In some Python code I've read I keep noticing this code: return dict(somekey=somevalue) Does that have any benefit over: return {somekey:somevalue} I tend to say no, since both objects will belong to the same dict type, but I may be wrong. ...

What .NET dictionary supports a "find nearest key" operation?

I'm converting some C++ code to C# and it calls std::map::lower_bound(k) to find an entry in the map whose key is equal to or greater than k. However, I don't see any way to do the same thing with .NET's SortedDictionary. I suspect I could implement a workaround using SortedList, but unfortunately SortedList is too slow (O(n) for inserti...

Searching the Mac OSX system dictionaries?

I'd like to search for words in the OS X system dictionary (or dictionaries) using a simple glob or regex rather than a known text. (Currently I'm using /usr/share/dict/words instead, but the OSX dict would be a lot nicer.) The Dictionary Services interface is quite limited and doesn't allow this, but it seems like DSGetTermRangeInStrin...

Why does Dictionary[index] throws a KeyNotFoundException but Hashtable[index] doesn't?

Any idea why this behaviour is different? ...

Storing ints in a Dictionary

As I understand, in Objective-C you can only put Objects into dictionaries. So if I was to create a dictionary, it would have to have all objects. This means I need to put my ints in as NSNumber, right? SOo... NSNumber *testNum = [NSNumber numberWithInt:varMoney]; NSMutableDictionary *dictionary = [[NSMutableDictionary alloc] i...

How To Pass a Dictionary To a Function

Alright, so I think I'm doing this the right way. I'm new to objective-C, so I'm not sure about the syntax... I have a set of code that I need to call multiple times, from different files. So I made a new class that has a method in it that I'll call and pass it the values that it needs. Because I am passing different values I've put ...

Converting an XML-document to a dictionary

I do not need to edit any XML-file or anything, this is only for reading and parsing. I want to be able to handle the XML-document as a dictionary, like: username = doc["username"];, but I can't find out how to "convert" the document. I've also encountered the problem with duplicate key-names, but that could be easlily avoided by appen...