Hello,
pls can somebody have a look at my script and tell me why I can't get a value from d1? (print d1). Thank you for help.
here is a script:
def subtract():
d1=file1(filename)
dd2=file2(filename)
res = dict()
print d1
## for key in d1:
## if key not in d2:
## res[key] = None
## print res
def file1(filename):
d1 = dict()
fp = open(filename)
for line in fp:
process_line1(line, d1)
return d1
def file2(filename):
d2 = dict()
fp = open(filename)
for line in fp:
process_line(line, d2)
return d2
def process_line1(line, d1):
line = line.replace('-', ' ')
for word in line.split():
word = word.strip(string.punctuation + string.whitespace)
word = word.lower()
d1[word] = d1.get(word, 0) +1
d1 = file1('emma.txt')
d2 = file2('words.txt')
emma.txt consist of these words:
Hossa-už-dlhšie patrí medzi najlepších hrácov v lige, ale to už všetci vedia, preto si nan dávajú velký pozor. Otvára sa tak šanca pre dalších, napríklad aj pre mna. Hossa vie vynikajúco pracovat s pukom, má výborný prehlad v hre," cituje ESPN krídelníka Troya Brouwera, ktorý po dvoch prihrávkach od staršieho z bratov Hossovcov dvakrát rozvlnil siet za gólmanom hostí Leightonom. Hossa Hossa Hossa Hossa Hossa Hossa Hossa Hossa Hossa Hossa Hossa Hossa Hossa Hossa Hossa Hossa Hossa Hossa Hossa
words.txt consist of these words:
Finding the words from the book that are not in the word list from words.txt is a problem you might recognize as set subtraction; that is, we want to find all the words from one set (the words in the book) that are not in another set (the words in the list).