dictionary

Anyone know a common-words list for IT terminology?

I need them for help in building a tag cloud which needs to include IT terms like java, testing, versioning, patterns, agile etc etc. Need a few hundred words at least. ...

Pythonic way to check if two dictionaries have the identical set of keys?

For example, let's say I have to dictionaries: d_1 = {'peter': 1, 'adam': 2, 'david': 3} and d_2 = {'peter': 14, 'adam': 44, 'david': 33, 'alan': 21} What's the cleverest way to check whether the two dictionaries contain the same set of keys? In the example above it should return False because d_2 contains the 'alan' key, which d_1...

form.cleaned_data as a dictionary

Why when I call a function like this : function(request, **form.cleaned_data) I can send form's data as a dictionary, but when I try doing like this : data = **form.cleaned_data I'm getting error ? ...

Arguments disappear from a dictionary when passed to a function

In my function I read user's data from session and store them in a dictionary. Next I'm sending it to 'register' function from registration.backend but the function somehow get's it empty and a KeyError is thrown. Where are my data gone ? The code from function calling 'register' function : data = request.session['temp_data'] email = da...

How to get all the info in XML into dictionary with Python

Let's say I have an XML file as follows. <A> <B> <C>"blah"</C> <C>"blah"</C> </B> <B> <C>"blah"</C> <C>"blah"</C> </B> </A> I need to read this file into a dictionary something like this. dict["A.B1.C1"] = "blah" dict["A.B1.C2"] = "blah" dict["A.B2.C1"] = "blah" dict["A.B2.C2"] = "blah" But the format of the dict doesn...

Transforming deeply nested dictionary to 1D dictionary with Python

I have some deeply randomly nested dictionary as follows. {'CompilationStatistics': {'CodeGeneration': {'EndTime': '2010-04-21T14:03:11', 'StartTime': '2010-04-21T14:03:11', 'StepList': {'EliminatingDuplicates': {'EndTime': '2010-04-21T14:03:11...

reverse mapping of dictionary with Python

If I have a dictionary named ref as follows ref = {} ref["abc"] = "def" I can get "def" from "abc" def mapper(from): return ref[from] But, how can I get from "def" from "abc"? def revmapper(to): ??? ...

WPF+MVVM: How to display VM via resource dictionary

At the moment I am creating new instance of both View and ViewModel and assign view.DataContext = vm in the application in the handler of 'Startup' application event In the http://msdn.microsoft.com/en-us/magazine/dd419663.aspx in the "Applying a View to a ViewModel" chapter I've read that it would be a good idea to bind ViewModel objec...

How do I concatenate strings from a dictionary by identifying the last item with Python?

I need to concatenate string to an existing one as follows. for k,v in r.iteritems(): tableGenString += "%s %s, " % (k, what_type(v)) The problem is that for the last item the comma(',') should not be added. How can I check if k,v is the last item? Added The example is a simplified version of the real code as follows. for k,v ...

how to send dictionary as a Querystring?

Hi, how to send the Dictionary as querystring and receive on another page in same type Dictionary. please guide me . ...

Python list comprehension for dictionaries in dictionaries?

I just learned about list comprehension, which is a great fast way to get data in a single line of code. But something's bugging me. In my test I have this kind of dictionaries inside the list: [{'y': 72, 'x': 94, 'fname': 'test1420'}, {'y': 72, 'x': 94, 'fname': 'test277'}] The list comprehension s = [ r for r in list if r['x'] > 92...

Sorting dicts (contained in lists) alphanumerically in Python

I'm having an issue with sorting a list that contains a dict. Currently I am sorting it by a key called 'title' with the following line: list.sort(key=operator.itemgetter('title')) The problem with this is that some of my data gets sorted looking like this: title_text #49 title_text #5 title_text #50 How would I go about sorting it...

NUnit Nested Collection Comparison

Is there something similar to CollectionAssert.AreEquivalent() that works with nested collections? The following code... CollectionAssert.AreEquivalent ( new Dictionary<int, Dictionary<int, string>> { { 1, new Dictionary < int, string > { { 10, "foo" }, { 11, "bar" }, { 12, "spam" } } }, { 2, new Dictionary < i...

Python convert string object into dictionary

Hi I have been working to build a complex data structure which would return a dictionary. Currently that class return string object of the form { cset : x, b1 : y, b2 : z, dep : { cset : x1, b1 : y1, b2 : z1, dep : { cset : ...

Need to look up key using string in a Dictionary<TKey, TValue> Class

I need to use a list pulled from sql, list is built from Dictionary<Int32, String> measurementTypes = this.GetIndicatorTypes(MeasurementTypeFilter.All); is ther a way to retrive the key using the string. Something like TypeID = measurementTypes.contains("GEN"); ...

Python: Finding a (string) key in a dictionary that contains a substring

In my script I build a dictionary of keys(albums) mapped to artists(values) so that I can do a quick lookup of what artists made what albums. However, I want the user to be able to find all albums which contain a substring. For example a search on "Light" should return [Light Chasers] = Cloud Cult and also [Night Light] = Au Revoir Sim...

How to unique a dict by value?

I want to unique duplicate values in a dict. It looks like this: d = { "a":1, "b":2, "c":2, "d":3, "e":4, "f":5, "g":1, "h":2, "i":2, "j":1, "k":1} Here is what I did: # sort and unique the dict values obj = d.values() K = [] K = sorted(list(zip(*[(x,K.append(x)) for x in obj if not x in K])[0] V=[] for v1 in L: V.append([k f...

c# enum and performance

My app has a lot of different lookup values, these values don't ever change, e.g. US States. Rather than putting them into database tables, I'd like to use enums. But, I do realize doing it this way involves having a few enums and a lot of casting from "int" and "string" to and from my enums. Alternative, I see someone mentioned using...

Problem Updating the the contents of Dictionary in foreach loop

Hi, I am writing a simple generic update extension for IEnumerable, this method used to join given 2 List of business objects or dictionaries using the given keys and updating the specific field. public static void Update<TOuter, TInner, TKey>(this IEnumerable<TOuter> outer, IEnumerable<TInner> Inner, Func<TOuter, TKey> OuterKeySelecto...

How to PROPERLY remove xmln:xsi and xmlns:xsd from xml dictionary serialization

Question: I use a serializable dictionary class, found at http://weblogs.asp.net/pwelter34/archive/2006/05/03/444961.aspx , to serialize a dictionary. It works fine with the example class below. <System.Xml.Serialization.XmlRoot("ccl")> _ Public Class ccl <System.Xml.Serialization.XmlElement("name")> _ Public xx As String = ""...