Skip to content

Commit 0183c07

Browse files
authored
Cleaned Up Challenge Code (#57)
* Reworking solutions files * Reworking solutions * Updated duplicates solutions * Added rounding solutions * Created cat function * Cleaned up existence * Created init files for testing purposes * Renamed files * Renamed all solutions files * Removed module file
1 parent f50d989 commit 0183c07

File tree

23 files changed

+135
-104
lines changed

23 files changed

+135
-104
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
1-
import solutions
1+
import capitalize
22
from inspect import getmembers, isfunction
33

44

55
def test_capitalize_all_lowercase():
6-
for _, value in getmembers(solutions, isfunction):
6+
for _, value in getmembers(capitalize, isfunction):
77
assert value("deku") == "Deku"
88

99

1010
def test_capitalize_no_alphabet():
11-
for _, value in getmembers(solutions, isfunction):
11+
for _, value in getmembers(capitalize, isfunction):
1212
assert value("1234") == "1234"
1313

1414

1515
def test_capitalize_all_caps():
16-
for _, value in getmembers(solutions, isfunction):
16+
for _, value in getmembers(capitalize, isfunction):
1717
assert value("TSUYU") == "Tsuyu"

challenges/how-to-check-if-a-key-exists-in-a-dictionary/solutions.py renamed to challenges/how-to-check-if-a-key-exists-in-a-dictionary/case_insensitive_lookup.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,10 @@
22
Provides a series of solutions to the challenge provided at the following link:
33
https://therenegadecoder.com/code/how-to-check-if-a-key-exists-in-a-dictionary-in-python/#challenge
44
"""
5+
from typing import Optional
56

67

7-
def case_insensitive_lookup_1(dictionary: dict, term: str):
8+
def case_insensitive_lookup_1(dictionary: dict, term: str) -> Optional[str]:
89
"""
910
Implements a case insensitive lookup using a try/catch.
1011
@@ -16,11 +17,11 @@ def case_insensitive_lookup_1(dictionary: dict, term: str):
1617
key = term.lower()
1718
try:
1819
return dictionary[key.lower()]
19-
except:
20+
except KeyError:
2021
return None
2122

2223

23-
def case_insensitive_lookup_2(dictionary: dict, term: str):
24+
def case_insensitive_lookup_2(dictionary: dict, term: str) -> Optional[str]:
2425
"""
2526
Implements a case insensitive lookup using the get() method.
2627
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import case_insensitive_lookup
2+
from inspect import getmembers, isfunction
3+
4+
5+
def test_case_insensitive_lookup_capital():
6+
dictionary = {
7+
"shrub": "a woody plant which is smaller than a tree and has several main stems arising at or near the ground."
8+
}
9+
for _, value in getmembers(case_insensitive_lookup, isfunction):
10+
assert value(dictionary, "Shrub") == dictionary["shrub"]

challenges/how-to-compute-absolute-value/solutions.py renamed to challenges/how-to-compute-absolute-value/absolute_value_text.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
"""
2-
Provides a series of solutions to the challenge provided at the following link:
2+
33
https://therenegadecoder.com/code/how-to-compute-absolute-value-in-python/#challenge
44
"""
55

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
"""
2+
Provides a series of solutions to the challenge provided at the following link:
3+
https://therenegadecoder.com/code/how-to-create-a-list-in-python/#challenge
4+
"""
5+
6+
7+
def fib_1():
8+
fibonacci = [1, 1]
9+
[fibonacci.append(fibonacci[i - 1] + fibonacci[i - 2]) for i in range(2, 100)]
10+
return fibonacci
11+
12+
13+
def fib_2():
14+
series = [1, 1]
15+
for i in range(2, 100):
16+
prev_1 = series[i - 1]
17+
prev_2 = series[i - 2]
18+
new = prev_1 + prev_2
19+
series.append(new)
20+
return series
21+
22+
23+
def fib_3():
24+
def recur(n):
25+
if n == 0 or n == 1:
26+
return 1
27+
else:
28+
return recur(n - 1) + recur(n - 2)
29+
series = []
30+
for i in range(100):
31+
number = recur(i)
32+
series.append(number)
33+
return series

challenges/how-to-create-a-list/list-comprehension.py

Lines changed: 0 additions & 4 deletions
This file was deleted.

challenges/how-to-create-a-list/loop.py

Lines changed: 0 additions & 14 deletions
This file was deleted.

0 commit comments

Comments
 (0)