The following bit of code is essentially just an extension for myself that organizes GitBook's summary.md file to be coherent to order of leetcode problem sets.
import collectionsimport redefgitbook_clean_summary(in_file):""" :type in_file: string :rtype: void """ file_out =open("SUMMARY_SORTED.md", "w")withopen(in_file, 'r')as file: lines = file.readlines() numbers = [int(re.search(r'\d+', line).group())for line in lines] elements =dict([(line, number) for number, line inzip(lines, numbers)]) sort_d = collections.OrderedDict(sorted(elements.items()))for key in sort_d: file_out.write('%s'% sort_d[key]) file_out.close()# note: SUMMARY.md must only contain 'LeetCode' parent folder# detecting no number in lines will cause an exception to be throwngitbook_clean_summary("SUMMARY.md")