Mercurial > pylearn
comparison misc.py @ 355:430c9e92cd23
Added common directory
author | Joseph Turian <turian@iro.umontreal.ca> |
---|---|
date | Thu, 19 Jun 2008 16:12:29 -0400 |
parents | 9e96fe8b955c |
children |
comparison
equal
deleted
inserted
replaced
354:d580b3a369a4 | 355:430c9e92cd23 |
---|---|
1 | |
2 def unique_elements_list_intersection(list1,list2): | |
3 """ | |
4 Return the unique elements that are in both list1 and list2 | |
5 (repeated elements in listi will not be duplicated in the result). | |
6 This should run in O(n1+n2) where n1=|list1|, n2=|list2|. | |
7 """ | |
8 return list(set.intersection(set(list1),set(list2))) | |
9 import time | |
10 #http://www.daniweb.com/code/snippet368.html | |
11 def print_timing(func): | |
12 def wrapper(*arg): | |
13 t1 = time.time() | |
14 res = func(*arg) | |
15 t2 = time.time() | |
16 print '%s took %0.3f ms' % (func.func_name, (t2-t1)*1000.0) | |
17 return res | |
18 return wrapper |