[Biopython-dev] [Bug 2631] Updated Bio.MaxEntropy to remove listfns import

bugzilla-daemon at portal.open-bio.org bugzilla-daemon at portal.open-bio.org
Mon Oct 27 16:55:04 UTC 2008


http://bugzilla.open-bio.org/show_bug.cgi?id=2631





------- Comment #4 from bsouthey at gmail.com  2008-10-27 12:55 EST -------
(In reply to comment #3)
> I don't know if it matters for MaxEntropy, but your re-implementation of
> Bio.listfns.itemindex does not preserve the current behaviour with duplicate
> entries:
> 
> >>> x = [1,2,3,3,2,5]
> >>> from Bio.listfns import itemindex
> >>> itemindex(x)
> {1: 0, 2: 1, 3: 2, 5: 5}
> >>> class2index ={}
> >>> for i, j in enumerate(x):
>         class2index.update({j:i})
> 
> >>> class2index
> {1: 0, 2: 4, 3: 3, 5: 5}
> 



In this case, x is a return type of the listfns.items() function, where the doc
string of listnfs:
"""items(l) -> list of items
    Generate a list of one of each item in l.  The items are returned
    in arbitrary order.
    """

Therefore duplicates are not allowed to occur (and duplicates would not make
sense anyhow). But in order to be similar to the original code, just avoid
updating if the key already exists:

class2index ={}
for i, j in enumerate(x):
    if not class2index.has_key(j):
        class2index.update({j:i})


-- 
Configure bugmail: http://bugzilla.open-bio.org/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the assignee for the bug, or are watching the assignee.



More information about the Biopython-dev mailing list