操作文件夹
import os
path = r"C:\路径"
f_list = os.listdir(path)
fold_list = []
file_list = []
for i in range(len(f_list)):
if os.path.isfile(os.path.join(path, f_list[i])):
fold_list.append(f_list[i])
print("是文件:" + f_list[i])
elif os.path.isdir(os.path.join(path, f_list[i])):
file_list.append(f_list[i])
print("是文件夹:" + f_list[i])
else:
print("nothing!")
print(fold_list)
print(file_list)
数字列表冒泡排序
import re
pic = [带数字的列表]
pic_last = []
m = re.compile(r"\d+")
n = len(pic)
for i in range(n):
for j in range(i, n):
if int(re.match(m, pic[i]).group()) > int(re.match(m, pic[j]).group()):
pic[i], pic[j] = pic[j], pic[i]
print(pic)