File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1- """This module contains code from
2- Think Python by Allen B. Downey
3- http://thinkpython.com
1+ """This module contains a code example related to
42
5- Copyright 2012 Allen B. Downey
6- License: GNU GPLv3 http://www.gnu.org/licenses/gpl.html
3+ Think Python, 2nd Edition
4+ by Allen Downey
5+ http://thinkpython2.com
76
7+ Copyright 2015 Allen Downey
8+
9+ License: http://creativecommons.org/licenses/by/4.0/
810"""
911
10- from anagram_sets import *
12+ from __future__ import print_function , division
13+
14+ import anagram_sets
15+
1116
1217def metathesis_pairs (d ):
1318 """Print all pairs of words that differ by swapping two letters.
1419
1520 d: map from word to list of anagrams
1621 """
17- for anagrams in d .itervalues ():
22+ for anagrams in d .values ():
1823 for word1 in anagrams :
1924 for word2 in anagrams :
2025 if word1 < word2 and word_distance (word1 , word2 ) == 2 :
21- print word1 , word2
26+ print ( word1 , word2 )
2227
2328
2429def word_distance (word1 , word2 ):
@@ -39,5 +44,5 @@ def word_distance(word1, word2):
3944
4045
4146if __name__ == '__main__' :
42- d = all_anagrams ('words.txt' )
43- metathesis_pairs (d )
47+ sets = anagram_sets . all_anagrams ('words.txt' )
48+ metathesis_pairs (sets )
Original file line number Diff line number Diff line change 1- """This module contains code from
2- Think Python by Allen B. Downey
3- http://thinkpython.com
1+ """This module contains a code example related to
42
5- Copyright 2012 Allen B. Downey
6- License: GNU GPLv3 http://www.gnu.org/licenses/gpl.html
3+ Think Python, 2nd Edition
4+ by Allen Downey
5+ http://thinkpython2.com
76
7+ Copyright 2015 Allen Downey
8+
9+ License: http://creativecommons.org/licenses/by/4.0/
810"""
911
10- import random
12+ from __future__ import print_function , division
1113
1214
1315def most_frequent (s ):
@@ -51,7 +53,7 @@ def read_file(filename):
5153
5254
5355if __name__ == '__main__' :
54- s = read_file ('words .txt' )
55- t = most_frequent (s )
56- for x in t :
57- print x
56+ string = read_file ('emma .txt' )
57+ letter_seq = most_frequent (string )
58+ for x in letter_seq :
59+ print ( x )
Original file line number Diff line number Diff line change 1- """This module contains code from
2- Think Python by Allen B. Downey
3- http://thinkpython.com
1+ """This module contains a code example related to
42
5- Copyright 2012 Allen B. Downey
6- License: GNU GPLv3 http://www.gnu.org/licenses/gpl.html
3+ Think Python, 2nd Edition
4+ by Allen Downey
5+ http://thinkpython2.com
76
7+ Copyright 2015 Allen Downey
8+
9+ License: http://creativecommons.org/licenses/by/4.0/
810"""
911
12+ from __future__ import print_function , division
13+
14+
1015def first (word ):
1116 """Returns the first character of a string."""
1217 return word [0 ]
@@ -31,8 +36,8 @@ def is_palindrome(word):
3136 return is_palindrome (middle (word ))
3237
3338
34- print is_palindrome ('allen' )
35- print is_palindrome ('bob' )
36- print is_palindrome ('otto' )
37- print is_palindrome ('redivider' )
39+ print ( is_palindrome ('allen' ) )
40+ print ( is_palindrome ('bob' ) )
41+ print ( is_palindrome ('otto' ) )
42+ print ( is_palindrome ('redivider' ) )
3843
You can’t perform that action at this time.
0 commit comments