From 385dafd1d12d8df9efd7f50df994bc4961da8c6c Mon Sep 17 00:00:00 2001 From: william Date: Sat, 23 Sep 2023 14:58:28 -0400 Subject: [PATCH] stuff --- 2-remove_dupe/duplicate.py | 15 ++++++++++++++- 4-sum_of_divisors/wtf.py | 6 ++++++ 7-word-count/count.py | 15 ++++++++++++++- 3 files changed, 34 insertions(+), 2 deletions(-) diff --git a/2-remove_dupe/duplicate.py b/2-remove_dupe/duplicate.py index 6eb0181..c5f329e 100644 --- a/2-remove_dupe/duplicate.py +++ b/2-remove_dupe/duplicate.py @@ -1,2 +1,15 @@ def remove_duplicate(string): - pass + last = '' + dups = '' + new_string = '' + for char in string: + if last == char: + dups += char + else: + new_string += char + last = char + + + return new_string, dups + +print(remove_duplicate("balloons")) \ No newline at end of file diff --git a/4-sum_of_divisors/wtf.py b/4-sum_of_divisors/wtf.py index 9d2e936..6f65ab8 100644 --- a/4-sum_of_divisors/wtf.py +++ b/4-sum_of_divisors/wtf.py @@ -12,3 +12,9 @@ def get_totatives(num): def totient(num): pass + +assert( compute_divisors(60) == [1, 2, 3, 4, 5, 6, 10, 12, 15, 20, 30, 60] ) +assert( sum_of_divisors(60) == 168 ) +assert( divisor_count(60) == 12 ) +assert( get_totatives(30) == [1, 7, 11, 13, 17, 19, 23, 29] ) +assert( totient(30) == 8 ) \ No newline at end of file diff --git a/7-word-count/count.py b/7-word-count/count.py index 885ad99..1bf1ab3 100644 --- a/7-word-count/count.py +++ b/7-word-count/count.py @@ -1,2 +1,15 @@ def word_stats(filename, n): - pass \ No newline at end of file + words = open(filename).read().replace('\n', '').lower().split() + words = [''.join(e for e in w if e.isalpha()) for w in words] + out = {} + for word in words: + if word in out.keys(): + out[word]['count'] += 1 + else: + out[word] = {'count': 0, 'word': word} + + out = sorted(out, key=lambda x:x[0]) + + return out + +o = word_stats('article.txt', 5)