dictionary

Python: Looping over One Dictionary and Creating Key/Value Pairs in a New Dictionary if Conditions Are Met

I want to compare the values of one dictionary to the values of a second dictionary. If the values meet certain criteria, I want to create a third dictionary with keys and value pairs that will vary depending on the matches. Here is a contrived example that shows my problem. edit: sorry about all the returns, but stack overflow is not...

Django POST sub-dictionaries

I'm making the following request through command-line cURL: curl -X POST http://localhost:8000/api/places/ -vvvv -d "place[name]=Starbucks" However, when I try to access the parameters by calling request.POST.getlist('place') I get an empty array as a response. How can I access the sub-dictionary which I can then pass to the ORM? ...

HTML Tag Cloud creation using Python?

Is there a library which can take a python dict with word freq = { 'abc' : 25, .... } and convert this into a html based Tag Cloud? ...

usual hashtable implementation compared to tree

Usually (as in C++), the hash function returns any size_t value -- thus many different hash values are possible (2^32). That is why I always thought that when people talked about them being implemented as tables, that is not really true in practice because the table would be much too big (2^32 entries). Of course my assumption was wrong...

How do I create a data structure that will be serialized this JSON format in python?

I have a function that accepts a list of date objects and should output the following dictionary in JSON: { "2010":{ "1":{ "id":1, "title":"foo", "postContent":"bar" }, "7":{ "id":2, "title":"foo again", "postContent":"bar baz boo" } }, "2009":{...

C#: Dictionary values to hashset conversion

Please, suggest the shortest way to convert Dictionary<Key, Value> to Hashset<Value> Is there built-in ToHashset() LINQ extension for IEnumerables ? Thank you in advance! ...

add append update and extend in python

Is there an article or forum discussion or something somewhere that explains why lists use append/extend but sets and dicts use add/update. I frequently find myself converting lists into sets and this difference makes that quite tedious so for my personal sanity I'd like to know what the rationalization is. The need to convert between ...

what do mean by "delegate" in iPhone application

Hi, all. I usually read a word 'delegate' in the apple document and their library book. What exactly meaning about this word? Any special meaning in iPhone? Thank you very much. ...

Many-to-many map - Not detecting changes to collection.

Hi, I have the following map in my entity: <map cascade="all-delete-orphan" inverse="true" name="ManyToMany" mutable="true" table="ManyToManyTable"> <key column="TableAId" /> <index column="EnumValueId" type="MyEnum, MyAssembly" /> <many-to-many column="TableBId" class="MyBClass, MyAssembly"/> </map> This creates the table fine...

How to make two directory-entries refer always to the same float-value

Consider this: >>> foo = {} >>> foo[1] = 1.0 >>> foo[2] = foo[1] >>> foo {1: 0.0, 2: 0.0} >>> foo[1] += 1.0 {1: 1.0, 2: 0.0} This is what happens. However, what I want would be that the last line reads: {1: 1.0, 2: 1.0} Meaning that both refer to the same value, even when that value changes. I know that the above works the way it ...

C# datatable, dictionary, datagridview

I have a project where I want to: 1) grab data from a sql server database, 2) pull the data into a c# program, 3) keep the data persistent - (store in a dictionary?) 4)view the data using a datagridview, 5) update the data, which would update the datagridview, the dictionary, and the database What would be the most efficient wa...

Filter Custom Dictionary with LINQ ToDictionary - "Unable to cast object of type 'System.Collections.Generic.Dictionary`2"

I have created a Dictionary class (MyDictionary for the example). I am currently trying to pass MyDictionary into a function, filter it into a new instance of MyDictionary and pass this new instance into another method. When I am attempting to create the second instance from the filtered first instance of MyDictionary via Lambda Expres...

Android Searchable Dictionary Example fails on Froyo 2.2

Hi I have used Searchable Dictionary Example in my application, compiled as 1.6, and used on my Nexus One with 2.1 with no problem. After updating my cell phone to 2.2., it stopped working when starting to type in the search field. I cannot debug for some reason (so I cannot provide log errors). Any ideas? Ohad ...

How to use list comprehension to add an element to copies of a dictionary?

given: template = {'a': 'b', 'c': 'd'} add = ['e', 'f'] k = 'z' I want to use list comprehension to generate [{'a': 'b', 'c': 'd', 'z': 'e'}, {'a': 'b', 'c': 'd', 'z': 'f'}] I know I can do this: out = [] for v in add: t = template.copy() t[k] = v out.append(t) but it is a little verbose and has no advantage over what I'm...

append multiple values for one key in Python dictionary

I am new to python and I have a list of years and values for each year. What I want to do is check if the year already exists in a dictionary and if it does, append the value to that list of values for the specific key. So for instance, I have a list of years and have one value for each year: 2010 2 2009 4 1989 8 2009 7 ...

Python converting the values from dicts into a tuples

I have a list of dictionaries that looks like this: [{'id':1,'name':'Foo'},{'id':2,'name':'Bar'}] I'd like to convert the values from each dict into a list of tuples like this: [(1,'Foo'),(2,'Bar')] How can I do this? ...

How to make persistent a python dictionary on google appengine

Using datastore framework of appengine, what's the pythonic way to make persistent a {}? ...

I need a language dictionary

I need to add dictionary facilities to an Asp.net MVC app. Does anyone know a library that I could use? Where can I get word definitions from? Any help is appreciated. ...

python: access multiple values in the value portion of a key:value pair

I am trying to perform a calculation on multiple values in the value portion of a list of key:value pairs. So I have something like: [('apples', ['254', '234', '23', '33']), ('bananas', ['732', '28']), ('squash', ['3'])] I'm trying to create a list of y-values that are the averages of those integers above. What I'm trying to write i...

using DictWriter in Python to write a subset of a dictionary's keys

I wrote a function that serializes a list of dictionaries as a CSV file using the CSV module. I sometimes want to write out to a file only a subset of each dictionary's keys however. I use the following code: def dictlist2file(dictrows, filename, fieldnames, delimiter='\t', lineterminator='\n'): out_f = open(filename, 'w') ...