Package Bio :: Module listfns
[hide private]
[frames] | no frames]

Module listfns

source code

This provides useful general functions for working with lists (OBSOLETE).

This module and its C code equivalent are considered to be obsolete, and are likely to be deprecated in a future release of Biopython, before being removed. Please get in touch via the mailing list if this will affect you. Many of these functions can be avoided using the python set object.

Functions: asdict Make the list into a dictionary (for fast testing of membership). items Get one of each item in a list. count Count the number of times each item appears. contents Calculate percentage each item appears in a list. itemindex Make an index of the items in the list. intersection Get the items in common between 2 lists. difference Get the items in 1 list, but not the other. indexesof Get a list of the indexes of some items in a list. take Take some items from a list.

Functions [hide private]
dictionary
asdict(l)
Return a dictionary where the keys are the items in the list, with arbitrary values.
source code
list of items
items(l)
Generate a list of one of each item in l.
source code
dict of counts of each item
count(items)
Count the number of times each item appears in a list of data.
source code
dict of item:percentage
contents(items)
Summarize the contents of the list in terms of the percentages of each item.
source code
list of common items
intersection(l1, l2)
Return a list of the items in both l1 and l2.
source code
list of items in l1, but not l2
difference(l1, l2)
Return a list of the items in l1, but not l2.
source code
dict of item : index of item
itemindex(l)
Make an index of the items in the list.
source code
list of indexes
indexesof(l, fn)
Return a list of indexes i where fn(l[i]) is true.
source code
list of just the indexes from l
take(l, indexes) source code
 
take_byfn(l, fn, opposite=0) source code
Function Details [hide private]

asdict(l)

source code 

Return a dictionary where the keys are the items in the list, with arbitrary values. This is useful for quick testing of membership.

Returns: dictionary

items(l)

source code 

Generate a list of one of each item in l. The items are returned in arbitrary order.

Returns: list of items

contents(items)

source code 

Summarize the contents of the list in terms of the percentages of each item. For example, if an item appears 3 times in a list with 10 items, it is in 0.3 of the list.

Returns: dict of item:percentage

intersection(l1, l2)

source code 

Return a list of the items in both l1 and l2. The list is in arbitrary order.

Returns: list of common items

difference(l1, l2)

source code 

Return a list of the items in l1, but not l2. The list is in arbitrary order.

Returns: list of items in l1, but not l2

itemindex(l)

source code 

Make an index of the items in the list. The dictionary contains the items in the list as the keys, and the index of the first occurrence of the item as the value.

Returns: dict of item : index of item