Reputation: 285
code snippet:
def after_equals(s):
return s.partition(' = ')[-1]
for k,s in zip(keyword, score):
print after_equals(k) + ',' + after_equals(s)
The output of the code prints:
NORTH,88466
GUESS,83965
DRESSES,79379
RALPH,74897
MATERIAL,68168
I need to output the into file. Please advice how to write to a file.
Upvotes: 0
Views: 125
Reputation: 363597
with open(filename, 'w') as out:
for k,s in zip(keyword, score):
print >> out, after_equals(k) + ',' + after_equals(s)
# note: ^^^
Upvotes: 2
Reputation: 1760
Open a file in write mode and write a string to the file, then close it:
f = file('myfile.txt','w')
f.write(s)
f.close()
For your case:
def after_equals(s):
return s.partition(' = ')[-1]
f = file('myfile.txt','w')
for k,s in zip(keyword, score):
f.write('%s,%s\n' % (after_equals(k), after_equals(s)))
f.close()
Upvotes: 1