1
0
Fork 0
mirror of https://github.com/vinta/awesome-python.git synced 2024-11-13 11:16:10 -05:00

apply PEP

This commit is contained in:
Vinta 2014-07-03 14:30:24 +08:00
parent 6cdb449271
commit a96f889892

19
sort.py
View file

@ -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()