def filter2(L, pattern, wildcard=None):
	"""
	Returns those tuples from sequence 'L' that matches
	'pattern'.  Elements of tuple are compare with corresponding
	element of 'pattern' - the test always pass if pattern's
	element has value 'wildcard'.

	>>> L = [(1, 2), (1, 3), (2, 3), (1, 4), (2, 1)]
	>>> filter2(L, (2,None))
	[(2, 3), (2, 1)]
	>>> filter2(L, (None,3))
	[(1, 3), (2, 3)]
	>>> filter2(L, (None,None))
	[(1, 2), (1, 3), (2, 3), (1, 4), (2, 1)]
	>>> filter2(L, (4,3))
	[]
	"""
	class Any:
		def __eq__(self, other): return 1
	any = Any()
	
	def f(x):
		if x==wildcard:
			return any
		else:
			return x

	pattern = tuple( map(f, list(pattern)) )
	return filter(lambda x: x==pattern, L)

