Created
April 6, 2012 22:09
-
-
Save jarodl/2323431 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def read_input(input_filename="input.txt"): | |
with open(input_filename) as f: | |
return (line.rstrip().split(' ') for line in f.readlines()) | |
def scramble_word(word): | |
if len(word) > 3: | |
from random import shuffle | |
middle = list(word[1:-1]) | |
shuffle(middle) | |
new_word = word[0] + str.join('', middle) + word[-1] | |
return new_word | |
else: | |
return word | |
def main(): | |
lines = read_input() | |
for words in lines: | |
scrambled = [scramble_word(word) for word in words] | |
print str.join(' ', scrambled) | |
if __name__ == '__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment