dictionary

Python equivalent of std::set and std::multimap

I'm porting a C++ program to Python. There are some places where it uses std::set to store objects that define their own comparison operators. Since the Python standard library has no equivalent of std::set (a sorted key-value mapping data structure) I tried using a normal dictionary and then sorting it when iterating, like this: def __...

Best way to support wildcard search a large dictionary?

I am working on a project to search in a large dictionary (100k~1m words). The dictionary items look like {key,value,freq}. Myy task is the development of an incremental search algoritm to support exact match, prefix match and wildcard match. The results should be ordered by freq. For example: the dictionary looks like key1=a,valu...

How do I store a dict/list in a database?

If I have a dictionary full of nested stuff, how do I store that in a database, as a string? and then, convert it back to a dictionary when I'm ready to parse? Edit: I just want to convert it to a string...and then back to a dictionary. ...

In Python, how do I loop through the dictionary and change the value if it equals something?

If the value is None, I'd like to change it to "" (empty string). I start off like this, but I forget: for k, v in mydict.items(): if v is None: ... right? ...

Create a Dictionary in xaml?

Pseudo example: <Window> <Window.Tag> <x:Dictionary KeyType="{x:Type sys:String}" ValueType="{x:Type sys:Int32}"> <sys:DictionaryEntry Entry="{sys:DictionaryEntry Key0, 000}"/> <sys:DictionaryEntry Key="key1" Value="111"/> <sys:DictionaryEntry> <sys:DictionaryEntry.Key> <sys:String>Key...

Python: Using vars() to assign a string to a variable

I find it very useful to be able to create new variables during runtime and create a dictionary of the results for processing later, i.e. writing to a file: myDict = {} for i in range (1,10): temp = "variable"+str(i) vars()[temp] = myFunctionThatReturnsData() # variable1= data1, variable2 = data2,etc. myDict[temp] = vars(te...

How to handle a generic dictionary whose types are unknown and don't matter?

If 'value' is an incoming generic dictionary whose types are unknown/don't matter, how do I take its entries and put them into a target dictionary of type IDictionary<object, object> ? if(type == typeof(IDictionary<,>)) { // this doesn't compile // value is passed into the method as object and must be cast IDictionar...

Python:Extend the 'dict' class

I have to solve this exercise: Python's dictionaries do not preserve the order of inserted data nor store the data sorted by the key. Write an extension for the dict class whose instances will keep the data sorted by their key value. Note that the order must be preserved also when new elements are added. and i'm freaking out.....i have...

Maximum length of cache keys in HttpRuntime.Cache object?

We are using HttpRuntime.Cache API in an ASP.NET to cache data retrieved from a database. For this particular application, our database queries feature a LOT of parameters, so our cache keys look something like this: table=table1;param1=somevalue1;param2=somevalue2;param3=somevalue3;param4=somevalue4;param5=somevalue5;param6=someval...

C# basic Dictionary Ordering Just need to clear an error

I adjusted this more and came up with the following code and I think my only problem is how I instruct it to read from textbox1 and output into textbox2 with the sorting instructions. I've been fighting this for days off and on if someone could help me out, thanks! using System; using System.Collections.Generic; using System.ComponentM...

Why am I getting no attribute '__getitem__' error for dictionary?

Why am I getting no attribute __getitem__ error for dictionary: Traceback (most recent call last): File "./thumbnail.py", line 39, in <module> main() File "./thumbnail.py", line 19, in main options['input_pattern'] AttributeError: Values instance has no attribute '__getitem__' Here's the code: #!/usr/bin/env python impor...

Render hyperlink control in Repeater

Hey everyone, I've got a repeater and it is bound to a dictionary . Although I can access the HyperLink, I can't render one. I have this code: <%# DataBinder.Eval((System.Collections.Generic.KeyValuePair<string, HyperLink>)Container.DataItem, "Value.NavigateUrl") %> The Value.NavigateUrl was a test to see if I could access that prop...

How can we have a dictionary service in android apps?

Is there any API available for dictionary service for android like that of Maps, Weather,etc.? How we can have a dictionary service in android apps? ...

pspell global namespace dictionary

Hi there, is it possible to create something like "a global dictionary" for pspell? I tried a lot but i can only create a personal dictionary for languages which are installed. Am im blind, or is there a better way than just insert a word for the global dictionary to the personal dictionary for each language? Best Regards, Beerweasle...

Need a thesaurus database

Is there an open source thesaurus available for download? It can be in any format. Preferably not from a 1915 dictionary. I need one to merge into a database application. ...

How do associations, @NS and @NV work in UniData Dictionaries?

Does anyone have a quick example of how Associations, @NS and @NV work in UniData? I’m trying to work out associations in dictionary items but cannot get them to do anything. For example, in a record <1,1> = A <1,2> = B <2,1> = Apple <2,2> = Banana I created 3 dictionary items. LETTER and FRUIT, COMBO as follows LETTER: <1> = D <2...

dict[obj] pulling wrong info at 35-36 xml node why?

I'm not sure how to explain this, but why isn't this code pulling the correct image and icon file? It continues to pull the wrong info at the line 35, which makes all other data one node behind. Even when I delete the three locations below, it still gets the xml wrong. Why would it be doing this? I verified the xml data and made sure al...

Python: does the set class "leak" when items are removed, like a dict?

I know that Python dicts will "leak" when items are removed (because the item's slot will be overwritten with the magic "removed" value)… But will the set class behave the same way? Is it safe to keep a set around, adding and removing stuff from it over time? Edit: Alright, I've tried it out, and here's what I found: >>> import gc >>>...

Dictionary-like object in Python that allows setting arbitrary attributes

What I want to do in my code: myobj = <SomeBuiltinClass>() myobj.randomattr = 1 print myobj.randomattr ... I can implement a custom SomeClass that implements __setattr__ __getattr__. But I wonder if there is already a built-in Python class or simple way to do this? ...

CUDA with map<value, key> & atomic operations

Hi, as far as i know i can use C++ templates in CUDA device code. So if i'm using map to create a dictionary will the operation of inserting new values be atomic? I want to count the number of appearances of a certain values, i.e. create a code-dictionary with probabilities of the codes. Thanks Macs ...