Documentation | Code | Download |
When you try to sort a list of strings that contain numbers, the normal python sort algorithm sorts lexicographically, so you might not get the results that you expect:
>>> a = ['a2', 'a9', 'a1', 'a4', 'a10']
>>> sorted(a)
['a1', 'a10', 'a2', 'a4', 'a9']
Notice that it has the order (‘1’, ‘10’, ‘2’) - this is because the list is being sorted in lexicographical order, which sorts numbers like you would letters (i.e. ‘b’, ‘ba’, ‘c’).
natsort provides a function natsorted that helps sort lists “naturally”, either as real numbers (i.e. signed/unsigned floats or ints), or as versions. Using natsorted is simple:
>>> from natsort import natsorted
>>> a = ['a2', 'a9', 'a1', 'a4', 'a10']
>>> natsorted(a)
['a1', 'a2', 'a4', 'a9', 'a10']
natsorted identifies real numbers anywhere in a string and sorts them naturally.
Documentation | Code | Download |
This module is a Python C extension that will convert strings to numbers much faster than can be done using pure Python. Additionally, if the string cannot be converted, instead of a ValueError the return value can be either the input as-is or a default value. To achieve this, the module makes some assumptions about the input type (input is int (or long), float, or str (or unicode)), and otherwise a TypeError is raised. Check out these timing results for just how much faster it can be.
Documentation | Code | Download |
input_reader is a python module that provides tools to help read the contents of a block-type input file. If you have ever written a custom parser for an input file, you will know that there are many non-obvious challenges that must be overcome, mostly in the realm of error handling. The challenges include dealing with unknown or missing keys, incorrect input (str vs float), data storage, and parse ordering. Handling these issues can make a seemingly easy task become a complicated mess that obscures the intent of your program.
The input_reader module was designed with a balance of conciseness and clarity in mind, as well as a strong resemblance to the argparse module in the python standard library. With input_reader, you can define how to read your input files in a relatively small number of lines (~1-2 per keyword) that are (for the most part) easy to read.
Simulate IR and Raman peaks with fast exchange. This is only useful if you are a vibrational spectroscopist.
API Documentation | Code |
The NPSpec library aids in solving the optical properties of nanoparticles. NPSpec provides interfaces for four languages: C, C++, Fortran, and Python.
This program is designed to find the volume of a nanoparticle using Monte Carlo integration. The volume of your nanoparticle is a nice thing to know in certain cases, because you can use it to
I’m sure there are many other wonderful uses, but these are why I am interested in the volume.
A template directory structure for a Fortran project using CMake as the build system.