dictionary

list of duplicate dictionaries copy single entry to another list

Hello, newbie question again. Let's say i have a list of nested dictionaries. a = [{"value1": 1234, "value2": 23423423421, "value3": norway, "value4": charlie}, {"value1": 1398, "value2": 23423412221, "value3": england, "value4": alpha}, {"value1": 1234, "value2": 23234231221, "value3": norway, "value4": charlie}, {"val...

tuple list from dict in python

How can I obtain a list of key-value tuples from a dict in python? Thanks ...

How to set initial size for a dictionary in Python?

I'm putting around 4 millions different keys into a python dictionary. Creating this dictionary takes about 15 minutes and consumes about 4GB memory on my machine. After dictionary is fully created, queering the dictionary is fast. I suspect that dictionary creation is so resource consuming as the dictionary is very often rehashed (as i...

Fastest ways to key-wise add a list of dicts together in python

Say I have a bunch of dictionaries a = {'x': 1.0, 'y': 0.5, 'z': 0.25 } b = {'w': 0.5, 'x': 0.2 } There's only two there, but the question is regarding an arbitary amount. What's the fastest way to find the mean value for each key? The dicts are quite sparse, so there will be a lot of cases where lots of keys aren't present in vario...

Copying a dictionary with multiple sub dictionaries and only returning certain keys from the sub dictionaries.

In my current iPhone project, I have a created a dictionary that groups the sub dictionaries by the first letter of the "Name" key. NSLog returns the following. I would like to create an identical dictionary that only shows the "Name" key under each initial letter key. What is the best way for making a copy of some of the items in the su...

Filtering a dictionary by the value for a key in the sub dictionaries with a UISearchBar

(Note: This is an extension of a previous question.) I am having some difficulty implementing a SearchBar for fairly complex tableview. The tableView has multiple sections, two lines of text and an image. All the data is loaded from a plist and then put into sections by the initial letter of the value for the "Name" key. NSLog returns t...

Using generic Dictionary over wcf: what do I need to look for?

Suppose I have a WCF service and a method in the contract <ServiceContract()> _ Interface IThingService '... <OperationContract()> _ Function GetThing(thingId As Guid) As Thing End Interface where Thing is an ordinary class with ordinary properties, except for one member: Public Class Thing ' ... Public Property Photos() As ...

How to parse dict output in a user friendly way in PHP?

Hi, I am trying to implement a dictionary-type service. I send a request with php using cURL to dict.org with the dict protocol. This is my code (which on its own works and may be helpful for future readers): $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, "dict://dict.org/define:(hello):english:exact"); curl_setopt($ch, CURLOPT_RETURN...

Using LINQ Dynamic Query Library with Dictionary<string, object> and .AsQueryable()

In one of my previous questions about using dynamically built up strings (where clauses) and using them in LINQ, I was guided towards the LINQ Dynamic Query Library Dynamic LINQ. The first issue was that it only applies to IQueryable, this however can be overcome by using the .AsQueryable() extension method on any IEnumerable. The prob...

How to delete entries in a dictionary with a given flag in python?

Hey! I have a dictionary, lets call it myDict, in Python that contains a set of similar dictionaries which all have the entry "turned_on : True" or "turned_on : False". I want to remove all the entries in myDict that are off, e.g. where "turned_on : False". In Ruby I would do something like this: myDict.delete_if { |id,dict| not dict[:...

Convert Python dict to object

Hi, I'm searching for an elegant way to convert a normal Python dict with some nested dicts to an object. For example: >>> d = {'a': 1, 'b': {'c': 2}, 'd': ["hi", {'foo': "bar"}]} Should be accessible in this way: >>> x = dict2obj(d) >>> x.a 1 >>> x.b.c 2 >>> x.d[1].foo bar I think, this is not possible without recursion, but wha...

How does Fast Enumeration (looping) work in Objective-C? (ie: for (NSString *aString in aDictionary)...)

I'm working on implementing a customized searchBar for a fairly complex table and have come across this code pattern AGAIN. This is a sample from the Beginning iPhone Development book: - (void)handleSearchForTerm:(NSString *)searchTerm { NSMutableArray *sectionsToRemove = [[NSMutableArray alloc] init]; [self resetSearch]; for (NSStrin...

Hash tables in prolog

I was solving a puzzle in prolog the other day and realized that were I using another programming language, I would have made use of a hash table/dictionary, but as far as I know this isn't really possible in prolog. So my first question is are there any prologs that support a dictionary-like data structure with the performance charact...

dictionary of object

hi all, I have a sorted dict { 1L: '<'New_Config (type: 'String') (id: 1L) (value: 4L) (name: 'account_receivable')'>', 2L: '<'New_Config (type: 'string') (id: 2L) (value: 5L) (name: 'account_payable')'>', 3L: '<'New_Config (type: 'String') (id: 3L) (value: 8L) (name: 'account_cogs ')'>', 4L: '<'New_Config (type: 'String') (id: 4L)(...

Key-ordered dict in python

Hello, I am looking for a solid implementation of an ordered associative array (in terms of keys, not of insertion order). More precisely, I am looking for a space-efficent implementation of a int-to-float (or string-to-float for another use case) mapping structure for which: Ordered iteration is O(n) Random access is O(1) The bes...

Throw a NullReferenceException while calling the set_item method of a Dictionary object in a multi-threding scenario

Our website has a configuration page such as "config.aspx", when the page initializing will load some infomations from a configuration file. To cache the loaded informations we provided a factory class and we call a public method of the factory to get the configuration instance when the page loaded. But sometimes when the Applciation Poo...

Free machine readable english dictionary required

I need an English dictionary that provides grammatical information about each word, for e.g. classification into nouns, verbs and so on. This is for semantic analysis. Format can be plain text, csv, xml or whatever. ...

convert Dictionary<int, Enumerable> to Dictionary<int, Enumerable> inverting content

for clarity lets say we have students and classes, its a many to many relationship. I have a Dictionary where the key is the student id and the Enumerable is a collection of classes(say we just have the id ) and I want to revert this to a Dictionary of classId, students is there a way to do this with Linq? I can think of a way to do th...

Getting rows from a SQL table matching a dictionary using LINQ

I have the following code snippet: var matchingAuthors = from authors in DB.AuthorTable where m_authors.Keys.Contains(authors.AuthorId) select authors; foreach (AuthorTableEntry author in matchingAuthors) { .... } where m_authors is a Dictionary containing th...

Reverse Dictionary<key, value>

Actually my previous question got me thinking and I realized that reversing a Dictionary is not trivial. What is the most elegant and readable way to do it? Same scenario student Many to Many with Classes original Dicitonary<int, List<int>> where the key is studentId and the Value is a List<int> that contains classId and want to revert...