Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 2 additions & 6 deletions sort.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,7 @@ def sort_blocks():
table_of_contents = ''.join(read_me.split('- - -')[0])
blocks = ''.join(read_me.split('- - -')[1]).split('\n# ')
for i in range(len(blocks)):

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lines 16-42 refactored with the following changes:

  • Replace if statement with if expression

if i == 0:
blocks[i] = blocks[i] + '\n'
else:
blocks[i] = '# ' + blocks[i] + '\n'

blocks[i] = blocks[i] + '\n' if i == 0 else '# ' + blocks[i] + '\n'
# Sorting the libraries
inner_blocks = sorted(blocks[0].split('##'))
for i in range(1, len(inner_blocks)):
Expand Down Expand Up @@ -56,7 +52,7 @@ def main():
s_line = line.lstrip()
indent = len(line) - len(s_line)

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lines 44-78 refactored with the following changes:

  • Replace unneeded comprehension with generator

if any([s_line.startswith(s) for s in ['* [', '- [']]):
if any(s_line.startswith(s) for s in ['* [', '- [']):
if indent == last_indent:
blocks[-1].append(line)
else:
Expand Down