Table of Contents

Module: listfns Bio/Tools/listfns.py

This provides useful general functions for working with lists.

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   
asdict
contents
count
difference
indexesof
intersection
itemindex
items
take
take_byfn
  asdict 
asdict ( l )

asdict(l) -> dictionary

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

  contents 
contents ( items )

contents(items) -> dict of item:percentage

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.

  count 
count ( items )

count(items) -> dict of counts of each item

Count the number of times each item appears in a list of data.

  difference 
difference ( l1,  l2 )

difference(l1, l2) -> list of items in l1, but not l2

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

  indexesof 
indexesof (
        l,
        fn,
        opposite=0,
        )

indexesof(l, fn) -> list of indexes

Return a list of indexes i where fn(l[i]) is true.

  intersection 
intersection ( l1,  l2 )

intersection(l1, l2) -> list of common items

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

  itemindex 
itemindex ( l )

itemindex(l) -> dict of item : index of item

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.

  items 
items ( l )

items(l) -> list of items

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

  take 
take ( l,  indexes )

take(l, indexes) -> list of just the indexes from l

  take_byfn 
take_byfn (
        l,
        fn,
        opposite=0,
        )


Table of Contents

This document was automatically generated on Mon Jul 1 12:03:03 2002 by HappyDoc version 2.0.1