Python includes exercises 99
Title: There are two disk files A and B, each store his letters, requested information from these two documents combined (in alphabetical order), output to a new file in C.
Program Analysis: None.
Source Code:
#!/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()
Before running the above program, you need to create test1.txt, test2.txt files in the directory script execution.
After the above procedure is successful, open the file test3.txt can see something like this:
123456