字符串
JavaScript 8种字符串反转的方法
· ☕ 2 分钟

在JavaScript中,如果要做字符串反转,我们第一时间会想到:

1

const str = “www.mzh.ren”;
str.split(’’).reverse().join(’’);
// “ner.hzm.www”

即,字符串转化为数组,调用数组的reverse()方法,连接数组成字符串。


Python 常用代码片段 1
· ☕ 1 分钟

1 获取文件名列表

import os
names = os.listdir('somedir')

如果要查找特定后缀名文件,你可能会考虑使用 glob 或 fnmatch 模块。比如:

import glob
pyfiles = glob.glob('somedir/*.py')

from fnmatch import fnmatch
pyfiles = [name for name in os.listdir('somedir')
            if fnmatch(name, '*.py')]

当然现在最好的还是 pathlib: