Python 99
[Python 100] Python 100
AB,,(), C
#!/usr/bin/python
# -*- coding: UTF-8 -*-
if __name__ == '__main__':
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()
test1.txttest2.txt
test3.txt
123456
[Python 100] Python 100
Sue
xxx***[email protected]
#!/usr/bin/python # -*- coding: UTF-8 -*- 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()Sue
xxx***[email protected]
Pt
idi***[email protected]
python3
# -*- coding: UTF-8 -*- with open('test1.txt') as f1, open('test2.txt') as f2, open('2.txt', 'w') as f3: for a in f1: b = f2.read() c = list(a + b) c.sort() d = '' d = d.join(c) f3.write(d)Pt
idi***[email protected]