"""
Script updates `README.md` with respect to files at ./easy and ./medium folders.
"""
import os

curr_dir = os.path.dirname(__file__)
with open(os.path.join(curr_dir, "README.md"), 'w') as readme:
    readme.write("# LeetCode\nDeliberate practice in coding.\n")
    langs = [l for l in os.listdir(curr_dir) if os.path.isdir(os.path.join(curr_dir, l)) and l[0] != '.']
    for lang in langs:
        readme.write("## {}\n".format(lang))
        readme.write("### Easy\n")
        easy = sorted(os.listdir(f"{curr_dir}/{lang}/easy"))
        easy = [x.split("_")[0] for x in easy]
        easy_solved = ""
        for el in easy:
            easy_solved += "{}, ".format(el)
        readme.write(easy_solved[:-2] + "\n")
        readme.write("### Medium\n")
        medium = sorted(os.listdir(f"{curr_dir}/{lang}/medium"))
        medium = [x.split("_")[0] for x in medium]
        medium_solved = ""
        for el in medium:
            medium_solved += "{}, ".format(el)
        readme.write(medium_solved[:-2] + '\n')

[((111, 136), 'os.path.dirname', 'os.path.dirname', (['__file__'], {}), '(__file__)\n', (126, 136), False, 'import os\n'), ((147, 182), 'os.path.join', 'os.path.join', (['curr_dir', '"""README.md"""'], {}), "(curr_dir, 'README.md')\n", (159, 182), False, 'import os\n'), ((289, 309), 'os.listdir', 'os.listdir', (['curr_dir'], {}), '(curr_dir)\n', (299, 309), False, 'import os\n'), ((496, 533), 'os.listdir', 'os.listdir', (['f"""{curr_dir}/{lang}/easy"""'], {}), "(f'{curr_dir}/{lang}/easy')\n", (506, 533), False, 'import os\n'), ((783, 822), 'os.listdir', 'os.listdir', (['f"""{curr_dir}/{lang}/medium"""'], {}), "(f'{curr_dir}/{lang}/medium')\n", (793, 822), False, 'import os\n'), ((327, 352), 'os.path.join', 'os.path.join', (['curr_dir', 'l'], {}), '(curr_dir, l)\n', (339, 352), False, 'import os\n')]