Advertisement
Guest User

Untitled

a guest
Nov 24th, 2012
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.14 KB | None | 0 0
  1. def apply_shifts(text, shifts):
  2.     """
  3.    Applies a sequence of shifts to an input text.
  4.  
  5.    text: A string to apply the Ceasar shifts to
  6.    shifts: A list of tuples containing the location each shift should
  7.    begin and the shift offset. Each tuple is of the form (location,
  8.    shift) The shifts are layered: each one is applied from its
  9.    starting position all the way through the end of the string.  
  10.    returns: text after applying the shifts to the appropriate
  11.    positions
  12.  
  13.    Example:
  14.    >>> apply_shifts("Do Androids Dream of Electric Sheep?", [(0,6), (3, 18), (12, 16)])
  15.    'JufYkaolfapxQdrnzmasmRyrpfdvpmEurrb?'
  16.    """
  17.     ### TODO.
  18.    
  19.     encoded_word = ""
  20.     a = dict(shifts)
  21.     for key in a:
  22.         if key == 0:
  23.             placeholder = apply_shift(text, a[key])
  24.             encoded_word = encoded_word + placeholder
  25.             print encoded_word
  26.         else:
  27.             placeholder = apply_shift(encoded_word[key:], a[key])
  28.             encoded_word = encoded_word[0:key] + placeholder[key:]
  29.             print encoded_word
  30.     return encoded_word
  31.    
  32. 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