comparison 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
comparison
equal deleted inserted replaced
356:18702ceb2096 357:2291a244a887
8 else: 8 else:
9 if i == 0: return 0 9 if i == 0: return 0
10 10
11 return +1 if i > 0 else -1 11 return +1 if i > 0 else -1
12 12
13 def percent_string(a, b):
14 assert a <= b
15 assert a >= 0
16 assert b > 0
17 return "%s of %s (%.2f%%)" % (a, b, 100.*a/b)
18
19 def unique_elements_list_intersection(list1,list2): 13 def unique_elements_list_intersection(list1,list2):
20 """ 14 """
21 Return the unique elements that are in both list1 and list2 15 Return the unique elements that are in both list1 and list2
22 (repeated elements in listi will not be duplicated in the result). 16 (repeated elements in listi will not be duplicated in the result).
23 This should run in O(n1+n2) where n1=|list1|, n2=|list2|. 17 This should run in O(n1+n2) where n1=|list1|, n2=|list2|.