This function takes a range in form of "a-b" and generate a list of numbers between a and b inclusive. Also accepts comma separated ranges like "a-b,c-d,f" will build a list which will include numbers from a to b, a to d...
Advertisement
Here is a quick and dirty way to sort a list of dictionary based on a key value.
One of the most frequently asked questions is how to efficiently get a list of Python dictionaries from a database query rather than the difficult-to-use list of tuples.
Group a list of items according to the starting character(s) of items. This is based on Raymond Hettinger's groupby class: http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/259173
Sometimes you get a list of lists and want to swap rows and columns, i.e. transpose the list. Yet, what if the rows have different lengths? Here is some advice you might find useful in such situations.
I often return result sets from a database call using a list of dictionary objects. When transmitting the pickled list object over the wire, the size of the pickle greatly effects the speed of the transmission.
I wrote this small class...
This module takes a list of equal length lists and converts it into XML.
If the first sublist is a list of headings, these are used to form the element names of the rest of the data, or these can be defined in the function call. Root...
This is an evolutionary algorithm that returns a random list of prime numbers. This code is highly inefficient for a reason. This algorithm is more of a proof of concept that if a prime was a heritable trait, it would not be a desired one.
Given an arbitrary list (of length >= 1) of positive integers, return the greatest common divisor (gcd) of the list.
What if you had a list like this: [1, -10, [1,2,[3,4]], xrange(200)], and you just wanted to go through each element in order (wanted it to return a simple list of [1,-10,1,2,3,4,1,2,3,4...199])
I've seen a couple of attempts to flatten...
This recipe returns a list of size n such that the contents of the returned list are random 0s and 1s. It returns a random binary list of size n.
This module/function lets you find a 2 dimensional list of indices for elements you are looking for in a super list. Example:
find([1,1,1,2,1,2,3,3],[1,2,3])
returns: [[0, 1, 2, 4], [3, 5], [6, 7]]
This is a little code for making a list that can have only items from a list of types
This script creates a scrolling list of buttons.
Here is a handy script that uses the simplex algorithm to compute an optimum list of refunds (for example, after a trip with shared expenses with friends).
It minimizes the number of transactions (refunds) required to reach the balance.
map() applies a function to a list of data sequentially. This is a variation to map that execute each function call concurrently in a thread.
Print (1) packages used by a binary, and (2) the list of installed patches related to these packages. If you have a binary that works with Solaris 10 update N, but doesn't with Solaris 10 update N-2, run this script on both platform and it...
This function find the percentile of a list of values. Note that the list must be sorted already.
I found my self want to express -string- in -list of regular expressions- and so I wrote this quick object to do the trick for me. It takes a list of strings containing regular expressions, compiles them into an internal list and then using the...
Uses the SIOCGIFCONF ioctl to obtain a list of interfaces and extracts those names, returning them in a list of strings. |