1
vote
1answer
43 views

Create palindrome by rearranging letters of a word

Inspired by a recent question that caught my interest, I wrote a function in Python 3.3 to rearrange the letters of a given string to create a (any!) palindrome: Count the occurrences of each letter ...
6
votes
4answers
152 views

Readability and Performance of my Trie implementation

As an interesting exercise in Python 3.3, I implemented a Trie (also known as a Prefix Tree). Example usages Create from list of key-value-tuples mapping = (('she', 1), ('sells', 5), ('sea', 10), ...
5
votes
1answer
97 views

Sparse Bitarray Class in Python (or rather frequently having contiguous elements with the same value)

Sparse is probably the wrong word - this is for encoding arrays of booleans where contiguous values tend to be the same. It'd be great to know a proper name for this data structure so I could read ...
2
votes
1answer
67 views

Longest-match lookup via nested dicts

I have the following datastructure to perform a longest-match lookup via nested dicts. For example. cs['a b c d'] with a and a b c being in the structure will return a b c and the remainder d. I ...
5
votes
1answer
627 views

Implementations of prefix lookup tables in Python

I've got a fairly performance sensitive need for fast prefix lookup, and I've built two different implementations trying to optimize for my use case. The first is built off a Trie implementation, and ...
2
votes
1answer
57 views

Generic pass_many(vals, pass_one) to unroll and call pass_one(val)?

I'm trying to create a generic function that takes a data-structure as input and then sends each non-empty item—e.g.: str, int—individually: def print_this(v, delim1="", delim2=""): print v, ...
3
votes
1answer
142 views

Review for Python mapping container in which every element is a key

I wanted to have a python container in which every element is a key (like in a set), but still supports mapping (like a dict) between the elements. To get a container which supports this idea the ...
2
votes
1answer
158 views

How to further modularize this file to make it more convenient and more readable?

Background is this question and to create something like cragislist or olx.com i.e. classifieds advertisement webapp / site and I've basically solved the problem and had a mess of unstructured code ...
1
vote
1answer
699 views

Here is my segment tree implementation in python, suggestions?

Fair warning, complete newbie to python, just wanted to implement something in python, Any suggestions welcome. Build tree with 10000 runs in 0.2 sec. Where as 10000 calls of query runs in around 30 ...
2
votes
1answer
120 views

Serialising missing values in trie

There are two aspects to this question that are inter-related. 1) Change I've made to the trie module in python (PyPI, github) to make it serialisable (and deserialisable). The change I made is ...