Advertisement
Guest User

Untitled

a guest
Aug 3rd, 2015
176
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.67 KB | None | 0 0
  1. def x_ian(x, word):
  2.     """
  3.    Given a string x, returns True if all the letters in x are
  4.    contained in word in the same order as they appear in x.
  5.  
  6.    >>> x_ian('eric', 'meritocracy')
  7.    True
  8.    >>> x_ian('eric', 'cerium')
  9.    False
  10.    >>> x_ian('john', 'mahjong')
  11.    False
  12.    
  13.    x: a string
  14.    word: a string
  15.    returns: True if word is x_ian, False otherwise
  16.    """
  17.     if len(x) == 1:
  18.         return x in word
  19.     else:
  20.         if word.find(x[0]) > word.find(x[1]):
  21.             return False
  22.         else:
  23.             try:
  24.                 return x_ian(x[1:], word[word.index(x[0]):])
  25.             except ValueError:
  26.                 return False
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement