擅长:python、mysql、java
<p>所以这可能太复杂了,但是</p>
<pre><code>def cipher(file1 = 'english.txt',
file2 = 'secret.txt',
file3 = 'cipher.txt'):
fh1 = open(file1, 'r') # open the files
fh2 = open(file2, 'r')
fh3 = open(file3, 'w+') # write this file if it doesn't exist
ls1 = list() # initiate lists
ls2 = list()
for line in fh1: # add the charecters to the list
for char in line:
ls1.append(char)
for line in fh2:
for char in line:
ls2.append(char)
if ' ' in ls1: # remove blank spaces
ls1.remove(' ')
if ' ' in ls2:
ls2.remove(' ')
print ls1, ls2
for i in range(len(ls1)): # traverse through the list and write things! :)
fh3.write(ls1[i] + ' ' + ls2[i] + '\n')
</code></pre>