很久之前我在Github上搞了一个LeetCode的仓库,但一直没怎么维护。最近发现自己刷了不少LC的题目了,想搬运到这个仓库上。

玩Github最重要的当然是写README了,MD的逼格决定了项目牛逼不牛逼。但是让我一个一个去手写项目中的链接那是不可能的,这辈子都不可能手写,只有写脚本自动生成才能满足装逼的样子。

import os
import os.path
# 根目录
rootdir="E:/gitTest/LeetCode/"
list=[]
result=[]
# 定义链接前缀
prefix="https://github.com/rever4433/LeetCode/tree/master/"
# 链接中的空格
space="%20"
for parent,dirnames,filenames in os.walk(rootdir):
    for dirname in dirnames:
        # 忽略的文件名
        if dirname == ".git":
            continue
      	# 文件夹名放入list
        if os.path.isdir(dirname):
            list.append(dirname)
        
        
    
for i in list:
    linkSuffix=i.replace(" ",space)
    # 生成MD链接,格式:### 1.[Invert Tree]() 
    i="### "+str(list.index(i)+1)+".["+i+"]("+prefix+linkSuffix+")"
    result.append(i)

with open('test.md','w') as fw:
    fw.write('%s'%'\n'.join(result))
    

相关文章:

  • 2021-11-28
  • 2021-12-15
  • 2021-06-15
  • 2021-07-29
  • 2021-04-14
  • 2021-11-30
  • 2021-11-27
  • 2021-10-23
猜你喜欢
  • 2022-01-08
  • 2022-12-23
  • 2021-04-16
  • 2021-12-07
  • 2022-01-28
  • 2021-12-01
  • 2021-11-03
相关资源
相似解决方案