apply PEP
This commit is contained in:
		
							
								
								
									
										17
									
								
								sort.py
									
									
									
									
									
								
							
							
						
						
									
										17
									
								
								sort.py
									
									
									
									
									
								
							| @@ -1,3 +1,5 @@ | |||||||
|  | # coding: utf-8 | ||||||
|  |  | ||||||
| """ | """ | ||||||
|     The approach taken is explained below. I decided to do it simply. |     The approach taken is explained below. I decided to do it simply. | ||||||
|     Initially I was considering parsing the data into some sort of |     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 ^.^. |     and flattening the end structure into a list of lines. Revision 2 maybe ^.^. | ||||||
| """ | """ | ||||||
|  |  | ||||||
|  |  | ||||||
| def main(): | 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: |     with open('README.md', 'r') as read_me_file: | ||||||
|         read_me = read_me_file.readlines() |         read_me = read_me_file.readlines() | ||||||
|  |  | ||||||
|     #Then we cluster the lines together as blocks |     # Then we cluster the lines together as blocks | ||||||
|     #Each block represents a collection of lines that should be sorted |     # Each block represents a collection of lines that should be sorted | ||||||
|     #This was done by assuming only links ([...](...)) are meant to be sorted |     # This was done by assuming only links ([...](...)) are meant to be sorted | ||||||
|     #Clustering is done by indentation |     # Clustering is done by indentation | ||||||
|     blocks = [] |     blocks = [] | ||||||
|     last_indent = None |     last_indent = None | ||||||
|     for line in read_me: |     for line in read_me: | ||||||
| @@ -37,9 +40,9 @@ def main(): | |||||||
|             last_indent = None |             last_indent = None | ||||||
|  |  | ||||||
|     with open('README.md', 'w+') as sorted_file: |     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] |         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)) |         sorted_file.write(''.join(blocks)) | ||||||
|  |  | ||||||
|  |  | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user