[frames] | no frames]

# Module algo

source code

Utility functions with algorithms.

 Classes
RunningTimeout
Class to calculate remaining timeout when doing several operations.
 Functions
list
 UniqueSequence(seq) Returns a list with unique elements. source code
list
 FindDuplicates(seq) Identifies duplicates in a list. source code

 _NiceSortTryInt(val) Attempts to convert a string to an integer. source code

 NiceSortKey(value) Extract key for sorting. source code
list
 NiceSort(values, key=None) Sort a list of strings based on digit and non-digit groupings. source code

 InvertDict(dict_in) Inverts the key/value mapping of a dict. source code
 Variables
_SORTER_GROUPS = `8`
_SORTER_RE = `re.compile("^%s(.*)\$" %(_SORTER_GROUPS* "(\D+|\d+...`
_SORTER_DIGIT = `re.compile("^\d+\$")`

Imports: re, time

 Function Details

### UniqueSequence(seq)

source code

Returns a list with unique elements.

Element order is preserved.

Parameters:
• `seq` (sequence) - the sequence with the source elements
Returns: list
list of unique elements from seq

### FindDuplicates(seq)

source code

Identifies duplicates in a list.

Does not preserve element order.

Parameters:
• `seq` (sequence) - Sequence with source elements
Returns: list
List of duplicate elements from seq

### NiceSort(values, key=None)

source code

Sort a list of strings based on digit and non-digit groupings.

Given a list of names `['a1', 'a10', 'a11', 'a2']` this function will sort the list in the logical order ```['a1', 'a2', 'a10', 'a11']```.

The sort algorithm breaks each name in groups of either only-digits or no-digits. Only the first eight such groups are considered, and after that we just use what's left of the string.

Parameters:
• `values` (list) - the names to be sorted
• `key` (callable or None) - function of one argument to extract a comparison key from each list element, must return string
Returns: list
a copy of the name list sorted with our algorithm

### InvertDict(dict_in)

source code

Inverts the key/value mapping of a dict.

Parameters:
• `dict_in` - The dict to invert
Returns:
the inverted dict

 Variables Details

### _SORTER_RE

Value:
 ```re.compile("^%s(.*)\$" %(_SORTER_GROUPS* "(\D+|\d+)?")) ```

 Generated by Epydoc 3.0.1 on Tue Jul 24 16:51:19 2012 http://epydoc.sourceforge.net