Today i made a python program to print common words in two files.
the code is.....,
#! usr/bin/env python
# filename : findwords.py
f1 = open('words.txt').readlines()
f2 = open('words1.txt').readlines()
if len(f1) != 0 | len(f2) != 0:
uniq1 = set(words for line in f1 for words in line.strip('\n\t').split(" "))
uniq2 = set(wordss for lines in f2 for wordss in lines.strip('\n\t').split(" "))
for words in uniq1:
for wordds in uniq2:
if words == wordds:
print words
i/p:
(words.txt)
this is a text string
this is another string
(word1.txt)
hello therer
this is a text string
actually really
sundelly peruchally
this is another string
this is a text string
o/p:
a
string
this
text
is
another
i hope u like it...
have fun :)
No comments:
Post a Comment