dictionary

C# Reverse items in Dictionary

Hi, I'm trying to reverse items in a dictionary in C#. I have tried: Dictionary<double, int> dict = new Dictionary<double, int>(); ...add itmes to it.... var v = dict.Reverse() However, dict.Reverse() gives me a type of IEnumberable>. I was just wondering how I could make it to a type of Dictionary? Thanks in advance. ...

using Python/Pexpect to crawl a network

Hi. This is more a logical thinking issue rather than coding. I already have some working code blocks - one which telnets to a device, one which parses results of a command, one which populates a dictionary etc etc Now lets say I want to analyse a network with unknown nodes, a,b,c etc (but I only know about 1) I give my code block node...

Using Python class as a data container

Sometimes it makes sense to cluster related data together. I tend to do so with a dict, e.g., self.group = dict(a=1, b=2, c=3) print self.group[a] One of my colleagues prefers to create a class class groupClass(object): def __init__(a, b, c): self.a = a self.b = b self.c = c self.group = groupClass(1, 2, ...

Has anyone parsed Wiktionary?

Wiktionary is a wiki dicitonary that covers many languages. It even has translations. I'd be interested in parsing it and playing with the data, has anyone does anything like this before? Is there any library I can use? (Preferable Python) ...

indexed switch statement, or equivalent? .net, C#

(added updates below) I'm wanting to build a method which accepts a string param, and an object which I would like to return a particular member of based on the param. So, the easiest method is to build a switch statement: public GetMemberByName(MyObject myobj, string name) { switch(name){ case "PropOne": return myobj.prop1; ...

Add elements in a list of dictionaries

I have a very long list of dictionaries with string indices and integer values. Many of the keys are the same across the dictionaries, though not all. I want to generate one dictionary in which the keys are the union of the keys in the separate dictionaries and the values are the sum of all the values corresponding to that key in each of...

Remove a given element from the other set in a dict of two sets

I have a dict, { "foo": set(["a", "b"]), "bar": set(["c", "d"]) }, and I'm given an element of one of the two sets and the name of the other set. I need to remove that element. How would I go about doing this? My best attempt so far is this: keys = dict.keys() if Element in dict[keys[0]].union(dict[keys[1]]): dict[keys[abs(keys.index(...

Dictionary Keys that match over a Date Range

I would like to store data in Generic Dictionary with keys that match over Date Ranges. For instance, I came up with the following idea public class MyKey : IEquatable<MyKey> { public int Key { get; set; } public DateTime StartDate { get; set; } public DateTime EndDate { get; set; } public override int GetHashCode() { ...

How to os.walk deep defaultdict for values?

I have a very large defaultdict(dict) that looks something like this: data['w']['x']['y']['z']={'a':5,'b':10} I'm trying to do produce a report that lists the hierarchy of all keys navigated for a particular final dictionary. In other words, I am looking for its "full pathname" as if the last dictionary were the file and the parent p...

name and value lookup collection, loaded from a dropdown list using beautifulsoup

On my html page I have a dropdown list: <select name="somelist"> <option value="234234234239393">Some Text</option> </select> So do get this list I am doing: ddl = soup.findAll('select', name="somelist") if(ddl): ??? Now I need help with this collection/dictionary, I want to be able to lookup by both 'Some Text' and 2342342...

Why doesn't mydict.items().sort() work?

When I try and sort my dictionary, I get an error: ''nonetype' object is not iterable. I am doing: for k,v in mydict.items().sort(): ...

Linq returning a IEnumerable<Dictionary<string,string>>

I need to return an IEnumerable of a dynamically created Dictionary. pseudo code: var x = from u in Users select new dictionary<string, string>{ Add("Name",u.Name), Add("LastName",u.LastName) } I've been trying many ways to get the pseudo code example above but no success... I would really appreciate your help. ...

Dictionary with integer array as a key.

I need a Dictionary whose key is an array of integers for example Dictionary<int[],string> or Dictionary<List<int>,string>. But I am quite surprised that the Equality method and hash code method is not defined for me. Is there any easy way to implement such a structure other than creating my own MyType: List<int> and to define all ne...

How to wrap a python dict?

I want to implement a class that will wrap -- not subclass -- the python dict object, so that when a change is detected in a backing store I can re-create the delegated dict object. I intend to check for changes in the backing store each time the dict is accessed for a read. Supposing I was to create an object to act like this; what met...

Python: How to "perfectly" override a dict

How can I make as "perfect" a subclass of dict as possible? The end goal is to have a simple dict in which the keys are lowercase. It would seem that should be some tiny set of primitives I can override to make this work, but all my research and attempts have made it seem like this isn't the case: If I override __getitem__/__setitem__...

help sorting a dictionary into another dictionary

I have a dictionary (index2) of 3-item lists, organized by key from 0-150 or so. I need to sort it into another dictionary, with the following constraints: 1.) all items attached to one key must stay together in the second dictionary 2.) length of items in the second dictionary must all be the same. To help with this one, I divided the t...

Do dictionaries have a has key method? I'm checking for 'None' and I'm having issues

I have 2 dictionaries, and I want to check if a key is in either of the dictionaries. I am trying: if dic1[p.sku] is not None: I wish there was a hasKey method, anyhow. I am getting an error if the key isn't found, why is that? ...

PHP - Words in a db - search via lexical dictionary (semantic similarity)

I'm implementing a small dictionary database where I'd like to do searches based on lexical/semantic similarity between them.. For example, beer has "sister words" such as soda, lemonade, wine, champagne each "different" in a "different direction" (in example: the first two are "moderate" versions of the idea of "beer", while the latte...

F# FSharpMap vs Dictionary performance

I was wondering how does the F# immutable Map perform against the standard Dictionary. I am writing a count function (for each line lookup increment set) to use on large files with millions of lines and thousands of elements. What about the memory usage? Thanks ...

NHibernate. Map 1-many Relationship to Dictionary.

Hi I'm trying to map a one-many parent-child relationship in NHibernate using XML mapping. Easy enough if the parent class instances store the collection of children in a list, but I want to use a dictionary. Can anyone point me to an example that shows how to set up this mapping in XML? In other words I want my parent class to look lik...