annotate misc.py @ 303:410a6ef674ed

added comment to source-version function
author James Bergstra <bergstrj@iro.umontreal.ca>
date Tue, 10 Jun 2008 11:07:20 -0400
parents 9e96fe8b955c
children 430c9e92cd23
rev   line source
49
718befdc8671 Miscellaneous general-purpose functions
bengioy@grenat.iro.umontreal.ca
parents:
diff changeset
1
718befdc8671 Miscellaneous general-purpose functions
bengioy@grenat.iro.umontreal.ca
parents:
diff changeset
2 def unique_elements_list_intersection(list1,list2):
718befdc8671 Miscellaneous general-purpose functions
bengioy@grenat.iro.umontreal.ca
parents:
diff changeset
3 """
718befdc8671 Miscellaneous general-purpose functions
bengioy@grenat.iro.umontreal.ca
parents:
diff changeset
4 Return the unique elements that are in both list1 and list2
718befdc8671 Miscellaneous general-purpose functions
bengioy@grenat.iro.umontreal.ca
parents:
diff changeset
5 (repeated elements in listi will not be duplicated in the result).
718befdc8671 Miscellaneous general-purpose functions
bengioy@grenat.iro.umontreal.ca
parents:
diff changeset
6 This should run in O(n1+n2) where n1=|list1|, n2=|list2|.
718befdc8671 Miscellaneous general-purpose functions
bengioy@grenat.iro.umontreal.ca
parents:
diff changeset
7 """
718befdc8671 Miscellaneous general-purpose functions
bengioy@grenat.iro.umontreal.ca
parents:
diff changeset
8 return list(set.intersection(set(list1),set(list2)))
229
d7250ee86f72 Added speed test for ArraDataSet
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 175
diff changeset
9 import time
d7250ee86f72 Added speed test for ArraDataSet
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 175
diff changeset
10 #http://www.daniweb.com/code/snippet368.html
d7250ee86f72 Added speed test for ArraDataSet
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 175
diff changeset
11 def print_timing(func):
d7250ee86f72 Added speed test for ArraDataSet
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 175
diff changeset
12 def wrapper(*arg):
d7250ee86f72 Added speed test for ArraDataSet
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 175
diff changeset
13 t1 = time.time()
d7250ee86f72 Added speed test for ArraDataSet
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 175
diff changeset
14 res = func(*arg)
d7250ee86f72 Added speed test for ArraDataSet
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 175
diff changeset
15 t2 = time.time()
d7250ee86f72 Added speed test for ArraDataSet
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 175
diff changeset
16 print '%s took %0.3f ms' % (func.func_name, (t2-t1)*1000.0)
d7250ee86f72 Added speed test for ArraDataSet
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 175
diff changeset
17 return res
d7250ee86f72 Added speed test for ArraDataSet
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 175
diff changeset
18 return wrapper