Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def apply_shifts(text, shifts):
- """
- Applies a sequence of shifts to an input text.
- text: A string to apply the Ceasar shifts to
- shifts: A list of tuples containing the location each shift should
- begin and the shift offset. Each tuple is of the form (location,
- shift) The shifts are layered: each one is applied from its
- starting position all the way through the end of the string.
- returns: text after applying the shifts to the appropriate
- positions
- Example:
- >>> apply_shifts("Do Androids Dream of Electric Sheep?", [(0,6), (3, 18), (12, 16)])
- 'JufYkaolfapxQdrnzmasmRyrpfdvpmEurrb?'
- """
- ### TODO.
- encoded_word = ""
- a = dict(shifts)
- for key in a:
- if key == 0:
- placeholder = apply_shift(text, a[key])
- encoded_word = encoded_word + placeholder
- print encoded_word
- else:
- placeholder = apply_shift(encoded_word[key:], a[key])
- encoded_word = encoded_word[0:key] + placeholder[key:]
- print encoded_word
- return encoded_word
- print apply_shifts("Do Androids Dream of Electric Sheep?", [(0,6), (3, 18), (12, 16)])
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement