

def main():
    alphabet = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'
    letters = []
    with open('garbage.txt', 'r') as garbage:
        for line in garbage.readlines():
            for c in line:
                if c in alphabet:
                    letters.append(c)

    print(''.join(letters))
    return 0


if __name__ == '__main__':
    main()


import string


def main():
    '''
    Hint: recognize the characters. maybe they are in the book,
    but MAYBE they are in the page source.
    Page source text saved in garbage.txt
    '''

    alphabet = string.ascii_letters
    with open('garbage.txt', 'r') as garbage:
        letters = [c for line in garbage.readlines() for c in line
                   if c in alphabet]
        # Long form of nested loops:
        # letters = []
        # for line in garbage.readlines():
        #     for c in line:
        #         if c in alphabet:
        #             letters.append(c)

    print(''.join(letters))
    return 0


if __name__ == '__main__':
    main()

Refactor code, add page hints
Refactor code, add page hints

+ 
+ import string
  
  
  def main():
-     alphabet = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'
-     letters = []
+     '''
+     Hint: recognize the characters. maybe they are in the book,
+     but MAYBE they are in the page source.
+     Page source text saved in garbage.txt
+     '''
+ 
+     alphabet = string.ascii_letters
      with open('garbage.txt', 'r') as garbage:
+         letters = [c for line in garbage.readlines() for c in line
+                    if c in alphabet]
+         # Long form of nested loops:
+         # letters = []
-         for line in garbage.readlines():
+         # for line in garbage.readlines():
-             for c in line:
+         #     for c in line:
-                 if c in alphabet:
+         #         if c in alphabet:
-                     letters.append(c)
+         #             letters.append(c)
  
      print(''.join(letters))
      return 0
  
  
  if __name__ == '__main__':
      main()
  
Refactor code, add page hints
## Code Before:


def main():
    alphabet = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'
    letters = []
    with open('garbage.txt', 'r') as garbage:
        for line in garbage.readlines():
            for c in line:
                if c in alphabet:
                    letters.append(c)

    print(''.join(letters))
    return 0


if __name__ == '__main__':
    main()

## Instruction:
Refactor code, add page hints
## Code After:

import string


def main():
    '''
    Hint: recognize the characters. maybe they are in the book,
    but MAYBE they are in the page source.
    Page source text saved in garbage.txt
    '''

    alphabet = string.ascii_letters
    with open('garbage.txt', 'r') as garbage:
        letters = [c for line in garbage.readlines() for c in line
                   if c in alphabet]
        # Long form of nested loops:
        # letters = []
        # for line in garbage.readlines():
        #     for c in line:
        #         if c in alphabet:
        #             letters.append(c)

    print(''.join(letters))
    return 0


if __name__ == '__main__':
    main()
