def rfind(s, sub, i = 0, last=None):
	"""rfind(s, sub [,start [,end]]) -> int

	Return the highest index in s where substring sub is found,
	such that sub is contained within s[start,end].  Optional
	arguments start and end are interpreted as in slice notation.

	Return -1 on failure.

	"""
	Slen = len(s)  # cache this value, for speed
	if last is None:
		last = Slen
	elif last < 0:
		last = max(0, last + Slen)
	elif last > Slen:
		last = Slen
	if i < 0: i = max(0, i + Slen)
	n = len(sub)
	m = last + 1 - n
	r = -1
	while i < m:
		if sub == s[i:i+n]: r = i
		i = i+1
	return r