view common/misc.py @ 357:2291a244a887

Added common.string
author Joseph Turian <turian@iro.umontreal.ca>
date Thu, 19 Jun 2008 16:27:02 -0400
parents 430c9e92cd23
children faece52be094
line wrap: on
line source

def sign(i, assertions=True):
    """
    + or - 1
    @precondition: i != 0
    """
    if assertions:
        assert i != 0
    else:
        if i == 0: return 0

    return +1 if i > 0 else -1

def unique_elements_list_intersection(list1,list2):
    """
    Return the unique elements that are in both list1 and list2
    (repeated elements in listi will not be duplicated in the result).
    This should run in O(n1+n2) where n1=|list1|, n2=|list2|.
    """
    return list(set.intersection(set(list1),set(list2)))