有兩個磁盤文件 A 和 B, 各存放一行字母,要求把這兩個文件中的信息合併(按字母順序排列), 輸出到一個新文件 C 中

fp = open('test1.txt', encoding='utf8')
a = fp.read()
fp.close()

fp = open('test2.txt', encoding='utf8')
b = fp.read()
fp.close()

fp = open('test3.txt', 'w', encoding='utf8')
l = list(a + b)
l.sort()
s = ''
s = s.join(l)
fp.write(s)
fp.close()
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章