1
vote
3answers
61 views

Optimization and accepted paradigms

This project was completed as part of an interview challenge. The feedback I received was: The code is neither optimized nor does it follow generally accepted paradigms, naming conventions or best ...
10
votes
1answer
1k views

Flask-SQLAlchemy models and unit-testing

This is my first time building anything remotely like a robust database. I'm midway through designing it and I would be grateful if you have suggestions or have found any logical errors. Goal: allow ...
3
votes
1answer
1k views

Create palindrome by rearranging letters of a word

Inspired by a recent question that caught my interest (now deleted), I wrote a function in Python 3 to rearrange the letters of a given string to create a (any!) palindrome: Count the occurrences of ...
4
votes
2answers
136 views

fractions data type — when to reduce?

Here is my Python implementation of a simple fractions class: ...
8
votes
3answers
542 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 ...
1
vote
0answers
67 views

numpy array as quasi-hash table

Motivation: I have a large number of large read-only dicts with large string keys mapped to tuples of two floats. They are taking up a large amount of heap space. Proposed solution: a 3xn numpy ...
3
votes
1answer
53 views

Converting float from arbitrary base to arbitrary base

I needed to write a small program to convert floats from any base to any other base. The thing is, it got big. I know there are other ways to implement the conversions (such as doing subtractions ...
3
votes
1answer
88 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 ...
7
votes
1answer
1k 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
0answers
2k views

Reading columns and rows in a .csv file

I have some data in a .csv file, which looks roughly like this: ...
1
vote
1answer
102 views

Combinatorial searching of Huffman trees

I need to search some data encoded by a Huffman tree, but not by simply walking the tree: I need test combinations of the data for a property and continue searching based on whether the test is ...
2
votes
4answers
802 views

What are the drawbacks of this “multi-key” dictionary?

I was making a relatively large-scale project in Python as a learning experiment, and in the process I found that it would be useful to have a map (or, in Python, I guess they're called dictionaries) ...
5
votes
1answer
159 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
66 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: ...
3
votes
1answer
164 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
195 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
871 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
125 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 ...