自己做网站犯法吗,移动互联网app开发,网站免费做招生宣传语,软文编辑器目录
99.有两个磁盘文件A和B,各存放一行字母,要求把这两个文件中的信息合并(按字母顺序排列), 输出到一个新文件C中
100.列表转换为字典 99.有两个磁盘文件A和B,各存放一行字母,要求把这两个文件中的信息合并(按字母顺序排列), 输出到一个新文件C中
#99
import string
fp o…目录
99.有两个磁盘文件A和B,各存放一行字母,要求把这两个文件中的信息合并(按字母顺序排列), 输出到一个新文件C中
100.列表转换为字典 99.有两个磁盘文件A和B,各存放一行字母,要求把这两个文件中的信息合并(按字母顺序排列), 输出到一个新文件C中
#99
import string
fp open(test1.txt) #打开并读取第一个文件
a fp.read()
fp.close()fp open(test2.txt) #打开并读取第二个文件
b fp.read()
fp.close()fp open(test3.txt,w) #打开并写入文件
l list(a b)
l.sort()
s
s s.join(l)
fp.write(s)
fp.close()
简单一点就是
def read(filename):f open(filename,r)a f.readlines()return a
s list(.join(read(test1.txt)read(test2.txt)))
s.sort()
s1 .join(s)
t open(test.txt,w)
t.writelines(s1)
t.close()
100.列表转换为字典
# 从列表创建字典
i [a,b,c]
l [1,2,3]
bdict(zip(i,l))
print(b)
返回 在这里如果同一键有多个键值则取最新的那个
# 从列表创建字典
i [a,b,c,c]
l [1,2,3,5]
bdict(zip(i,l))
print(b)
返回