def contains(string, char):
    for i in range(len(string) - 1, -1, -1):
        if string[i] == char:
            return i
raise ValueError('could not find %r in %r' % (char, string))
contains('bababa', 'k')
contains('bababa', 'a')
contains('bababa', 'b')
contains('xbababa', 'x')
How to raise a ValueError?