diff --git a/sort.py b/sort.py index 2ca73f7d..d8091009 100644 --- a/sort.py +++ b/sort.py @@ -1,3 +1,5 @@ +# coding: utf-8 + """ The approach taken is explained below. I decided to do it simply. Initially I was considering parsing the data into some sort of @@ -11,15 +13,16 @@ and flattening the end structure into a list of lines. Revision 2 maybe ^.^. """ + def main(): - #First, we load the current README into memory as an array of lines + # First, we load the current README into memory as an array of lines with open('README.md', 'r') as read_me_file: read_me = read_me_file.readlines() - #Then we cluster the lines together as blocks - #Each block represents a collection of lines that should be sorted - #This was done by assuming only links ([...](...)) are meant to be sorted - #Clustering is done by indentation + # Then we cluster the lines together as blocks + # Each block represents a collection of lines that should be sorted + # This was done by assuming only links ([...](...)) are meant to be sorted + # Clustering is done by indentation blocks = [] last_indent = None for line in read_me: @@ -37,11 +40,11 @@ def main(): last_indent = None with open('README.md', 'w+') as sorted_file: - #Then all of the blocks are sorted individually + # Then all of the blocks are sorted individually blocks = [''.join(sorted(block, key=lambda s: s.lower())) for block in blocks] - #And the result is written back to README.md + # And the result is written back to README.md sorted_file.write(''.join(blocks)) - + if __name__ == "__main__": main()