Compare commits
2 Commits
Author | SHA1 | Date | |
---|---|---|---|
385dafd1d1 | |||
1e1e8f1f03 |
@ -1,2 +1,12 @@
|
||||
def titlecase(string, exceptions):
|
||||
pass
|
||||
words = string.lower().split(' ')
|
||||
new_words = []
|
||||
for word in words:
|
||||
if word in exceptions:
|
||||
new_words.append(word)
|
||||
else:
|
||||
new_words.append(word.capitalize())
|
||||
|
||||
return ' '.join(new_words)
|
||||
|
||||
print(titlecase('the quick brown fox jumps over the lazy dog', ['jumps', 'the', 'over']))
|
@ -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"))
|
@ -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 )
|
@ -1,2 +1,15 @@
|
||||
def word_stats(filename, n):
|
||||
pass
|
||||
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)
|
||||
|
Loading…
x
Reference in New Issue
Block a user