Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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?
- """
- ""
- s = find_best_shifts_rec(wordlist, text, 0)
- shifts = []
- s.reverse()
- for c in s:
- new = (c[0], -(c[1]))
- shifts.append(new)
- return shifts
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement