kristofer revised this gist . Go to revision
1 file changed, 8 insertions
sumdisc.py(file created)
| @@ -0,0 +1,8 @@ | |||
| 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) | |
kristofer revised this gist . Go to revision
1 file changed, 23 insertions
stopwords.py(file created)
| @@ -0,0 +1,23 @@ | |||
| 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 | + | ||