List

Last modified: May 26, 2011

Contents

all_subsets

object all_subsets (object list, int size)

Returns:object
Category:List
Defined in:listutilities.py
Author:Michael Droettboom and Karl MacMillan

Returns all subsets of size size of the given list.

median

object median (object list, bool inlist = False)

Returns:object
Category:List
Defined in:listutilities.py
Author:Christoph Dalitz

Compute the median from a list of values in linear time.

This implementation works both with builtin numeric types like int or float, and with user defined types. For user defined type, you must implement the "less than" operator (__lt__), as in the following example:

class P:
   x = 0; y = 0
   def __init__(self, x, y):
       self.x = x; self.y = y
   def __lt__(self, other):
       return (self.x < other.x)
   def __eq__(self, other):
       return (self.x == other.x)

a = [P(0,0), P(1,1), P(2,0)]
p = median(a)

When the parameter inlist is True, the median is always a list entry, even for lists of even size. Otherwise, the median is for an even size list of int or float values the mean between the two middle values. So if you need the median for a pivot element, set inlist to True.

For user defined types, the returned median is always a list entry, because arithmetic computations do not make sense in this case.

Note

This is not the median image filter that replaces each pixel value with the median of its neighborhood. For this purpose, see the rank plugin.

permute_list

int permute_list (object list)

Returns:int
Category:List
Defined in:listutilities.py
Author:Michael Droettboom and Karl MacMillan

Permutes the given list (in place) one step.

Returns True if there are more permutations to go. Returns False if permutations are done.

Example usage:

>>>from gamera.plugins import listutilities
>>>a = [1,2,3]
>>>while listutilities.permute_list(a):
...    print a
...
[2, 1, 3]
[1, 3, 2]
[3, 1, 2]
[2, 3, 1]
[3, 2, 1]