fi =open("a.txt",'r', encoding='gbk')
fo =open("c.txt",'w', encoding='gbk')
txt = fi.read()
d ={}for c in txt:if0x4e00<=ord(c)<=0x9fa5:
d[c]= d.get(c,0)+1
ls =[]for key in d:
ls.append("{}(0x{:x}):{}".format(key,ord(key), d[key]))
fo.write(",".join(ls))
fi.close()
fo.close()
2、中文版凯撒加密
s =input("请输入明文:")
d ={}for c in[0x4e00,0x9fa5]:for i inrange(20902):
d[chr(i+c)]=chr((i+10451)%20902+c)print("凯撒加密后的文字:"+" ".join([d.get(c, c)for c in s]))
3、提取网页链接,即“href=”后面的的链接
fi =open("sweb.html",'r', encoding='utf-8')
fo =open("text-urls.txt",'w', encoding='utf-8')
txt = fi.read()
ls = txt.split(" ")
urls =[]for item in ls:if item[:5]=="href="and item[6:13]=="http://":
urls.append(item[6:-1])for item in urls:
fo.write(item+'\n')
fi.close()
fo.close()