stopwords.py
· 480 B · Python
Raw
def countwords(lst):
word_count = {}
for word in lst:
if word in word_count:
word_count[word] += 1
else:
word_count[word] = 1
return word_count
def wordsOfLength(w, n):
result = []
for word, count in w.items():
if count >= n:
result.append(word)
return result
def stopWords(text, k):
l = text.split()
w = countwords(l)
results = wordsOfLength(w, k)
return results
| 1 | def countwords(lst): |
| 2 | word_count = {} |
| 3 | |
| 4 | for word in lst: |
| 5 | if word in word_count: |
| 6 | word_count[word] += 1 |
| 7 | else: |
| 8 | word_count[word] = 1 |
| 9 | return word_count |
| 10 | |
| 11 | def wordsOfLength(w, n): |
| 12 | result = [] |
| 13 | for word, count in w.items(): |
| 14 | if count >= n: |
| 15 | result.append(word) |
| 16 | return result |
| 17 | |
| 18 | def stopWords(text, k): |
| 19 | l = text.split() |
| 20 | w = countwords(l) |
| 21 | results = wordsOfLength(w, k) |
| 22 | return results |
| 23 | |
| 24 |
sumdisc.py
· 217 B · Python
Raw
def shopping_total(n, items):
#print("f", n, items)
tot = 0.0
disc = lambda price: price * 0.9 if price > 50 else price
for a, price in items:
tot = tot + disc(price)
return round(tot, 1)
| 1 | |
| 2 | def shopping_total(n, items): |
| 3 | #print("f", n, items) |
| 4 | tot = 0.0 |
| 5 | disc = lambda price: price * 0.9 if price > 50 else price |
| 6 | for a, price in items: |
| 7 | tot = tot + disc(price) |
| 8 | return round(tot, 1) |
| 9 |