I need a reversible hash function (obviously the input will be much smaller in size than the output) that maps the input to the output in a random-looking way. Basically, I want a way to transform a number like “123” to a larger number like “9874362483910978”, but not in a way that will preserve comparisons, so it must not be
Python: sort function breaks in the presence of nan
sorted([2, float(‘nan’), 1]) returns [2, nan, 1] (At least on Activestate Python 3.1 implementation.) I understand nan is a weird object, so I wouldn’t be surprised if it shows up in random places in the sort result. But it also messes up the sort for the non-nan numbers in the container, which is really unexpected. I asked a related question
counting odd numbers in a list python
This is a part of my homework assignment and im close to the final answer but not quite yet. I need to write a function that counts odd numbers in a list. Create a recursive function count_odd(l) which takes as its only argument a list of integers. The function will return a count of the number of list elements that
SQLAlchemy: What’s the difference between flush() and commit()?
What the difference is between flush() and commit() in SQLAlchemy? I’ve read the docs, but am none the wiser – they seem to assume a pre-understanding that I don’t have. I’m particularly interested in their impact on memory usage. I’m loading some data into a database from a series of files (around 5 million rows in total) and my session
python: is it possible to attach a console into a running process
I just want to see the state of the process, is it possible to attach a console into the process, so I can invoke functions inside the process and see some of the global variables. It’s better the process is running without being affected(of course performance can down a little bit) Answer If you have access to the program’s source-code,
Python : terminology ‘class’ VS ‘type’
Just a simple question : when should I use the term ‘class’, and when should I use the term ‘type’ in Python ? is ‘class’ only for user-defined types, and ‘type’ for built-in types ? or now that everything is a type … should I use always ‘type’ even for user-defined classes ? … ? Answer It is more or
How do I convert a Python list into a C array by using ctypes?
If I have the follow 2 sets of code, how do I glue them together? How can I call the c_function with a contiguous list of elements in x? I tried to cast x to a c_void_p, but that didn’t work. I also tried to use something like but this gets a syntax error. The C code clearly wants the
Using a regular expression to replace upper case repeated letters in python with a single lowercase letter
I am trying to replace any instances of uppercase letters that repeat themselves twice in a string with a single instance of that letter in a lower case. I am using the following regular expression and it is able to match the repeated upper case letters, but I am unsure as how to make the letter that is being replaced
Interactively validating Entry widget content in tkinter
What is the recommended technique for interactively validating content in a tkinter Entry widget? I’ve read the posts about using validate=True and validatecommand=command, and it appears that these features are limited by the fact that they get cleared if the validatecommand command updates the Entry widget’s value. Given this behavior, should we bind on the KeyPress, Cut, and Paste events
Finding the most frequent character in a string
I found this programming problem while looking at a job posting on SO. I thought it was pretty interesting and as a beginner Python programmer I attempted to tackle it. However I feel my solution is quite…messy…can anyone make any suggestions to optimize it or make it cleaner? I know it’s pretty trivial, but I had fun writing it. Note: