Skip to content

Commit 3a3a011

Browse files
committed
fix sort.py
1 parent 6041c0b commit 3a3a011

1 file changed

Lines changed: 11 additions & 10 deletions

File tree

sort.py

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,31 +12,32 @@
1212
This could be extended by having nested blocks, sorting them recursively
1313
and flattening the end structure into a list of lines. Revision 2 maybe ^.^.
1414
"""
15+
1516
def sort_blocks():
1617
# First, we load the current README into memory
1718
with open('README.md', 'r') as read_me_file:
1819
read_me = read_me_file.read()
19-
20+
2021
# Separating the 'table of contents' from the contents (blocks)
2122
table_of_contents = ''.join(read_me.split('- - -')[0])
2223
blocks = ''.join(read_me.split('- - -')[1]).split('\n# ')
2324
for i in range(len(blocks)):
2425
if i == 0:
25-
blocks[i] = blocks[i]+'\n'
26+
blocks[i] = blocks[i] + '\n'
2627
else:
27-
blocks[i] = '#' + blocks[i]+'\n'
28-
29-
# Sorting the libraries
28+
blocks[i] = '# ' + blocks[i] + '\n'
29+
30+
# Sorting the libraries
3031
inner_blocks = sorted(blocks[0].split('##'))
3132
for i in range(1 , len(inner_blocks)):
3233
if inner_blocks[i][0] != '#':
33-
inner_blocks[i]='##'+inner_blocks[i]
34+
inner_blocks[i] = '##' + inner_blocks[i]
3435
inner_blocks=''.join(inner_blocks)
3536

3637
# Replacing the non-sorted libraries by the sorted ones and gathering all at the final_README file
3738
blocks[0] = inner_blocks
38-
final_README = table_of_contents + '- - -'+ ''.join(blocks)
39-
39+
final_README = table_of_contents + '- - -' + ''.join(blocks)
40+
4041
with open('README.md', 'w+') as sorted_file:
4142
sorted_file.write(final_README)
4243

@@ -70,10 +71,10 @@ def main():
7071
blocks = [''.join(sorted(block, key=lambda s: s.lower())) for block in blocks]
7172
# And the result is written back to README.md
7273
sorted_file.write(''.join(blocks))
73-
74+
7475
# Then we call the sorting method
7576
sort_blocks()
76-
77+
7778

7879
if __name__ == "__main__":
7980
main()

0 commit comments

Comments
 (0)