Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Problem 4: Multi-level decryption.
- #
- def find_best_shifts(wordlist, text):
- """
- Given a scrambled string, returns a shift key that will decode the text to
- words in wordlist, or None if there is no such key.
- Hint: Make use of the recursive function
- find_best_shifts_rec(wordlist, text, start)
- wordlist: list of words
- text: scambled text to try to find the words for
- returns: list of tuples. each tuple is (position in text, amount of shift)
- Examples:
- >>> s = random_scrambled(wordlist, 3)
- >>> s
- 'eqorqukvqtbmultiform wyy ion'
- >>> shifts = find_best_shifts(wordlist, s)
- >>> shifts
- [(0, 25), (11, 2), (21, 5)]
- >>> apply_shifts(s, shifts)
- 'compositor multiform accents'
- >>> s = apply_shifts("Do Androids Dream of Electric Sheep?", [(0,6), (3, 18), (12, 16)])
- >>> s
- 'JufYkaolfapxQdrnzmasmRyrpfdvpmEurrb?'
- >>> shifts = find_best_shifts(wordlist, s)
- >>> print apply_shifts(s, shifts)
- Do Androids Dream of Electric Sheep?
- """
- def find_best_shifts_rec(wordlist, text, start):
- """
- Given a scrambled string and a starting position from which
- to decode, returns a shift key that will decode the text to
- words in wordlist, or None if there is no such key.
- Hint: You will find this function much easier to implement
- if you use recursion.
- wordlist: list of words
- text: scambled text to try to find the words for
- start: where to start looking at shifts
- returns: list of tuples. each tuple is (position in text, amount of shift)
- """
- ### TODO.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement