diff --git a/ch02-strings/e08b2_last_word_in_file.py b/ch02-strings/e08b2_last_word_in_file.py index 4a4ab72..78b6d59 100755 --- a/ch02-strings/e08b2_last_word_in_file.py +++ b/ch02-strings/e08b2_last_word_in_file.py @@ -9,9 +9,7 @@ def last_word_alphabetically(filename): """ output = '' for one_line in open(filename): - for one_word in one_line.split(): - if not one_word.isalpha(): - continue - if one_word > output: - output = one_word + split_line=one_line.split() + split_line.append(output) + output=max(split_line) return output diff --git a/ch02-strings/e08b3_longest_word_in_file.py b/ch02-strings/e08b3_longest_word_in_file.py index 9557144..c17fada 100755 --- a/ch02-strings/e08b3_longest_word_in_file.py +++ b/ch02-strings/e08b3_longest_word_in_file.py @@ -8,9 +8,7 @@ def longest_word(filename): """ output = '' for one_line in open(filename): - for one_word in one_line.split(): - if not one_word.isalpha(): - continue - if len(one_word) > len(output): - output = one_word + split_line=one_line.split() + split_line.append(output) + output=max(split_line) return output