Skip to content

Commit 42bdcef

Browse files
post-workshop updates
1 parent d4f73c7 commit 42bdcef

13 files changed

Lines changed: 110 additions & 2 deletions

5_tdd_with_llms/examples/filter_and_sort_dictionaries/0_docstring.py renamed to 5_tdd_with_llms/examples/filter_and_sort_dictionaries_with_llm/0_docstring.py

File renamed without changes.

5_tdd_with_llms/examples/filter_and_sort_dictionaries/1a_generated_tests.py renamed to 5_tdd_with_llms/examples/filter_and_sort_dictionaries_with_llm/1a_generated_tests.py

File renamed without changes.

5_tdd_with_llms/examples/filter_and_sort_dictionaries/1b_manual_refactor_tests.py renamed to 5_tdd_with_llms/examples/filter_and_sort_dictionaries_with_llm/1b_manual_refactor_tests.py

File renamed without changes.

5_tdd_with_llms/examples/filter_and_sort_dictionaries/2a_generated_function.py renamed to 5_tdd_with_llms/examples/filter_and_sort_dictionaries_with_llm/2a_generated_function.py

File renamed without changes.

5_tdd_with_llms/examples/filter_and_sort_dictionaries/2b_manual_refactor_function.py renamed to 5_tdd_with_llms/examples/filter_and_sort_dictionaries_with_llm/2b_manual_refactor_function.py

File renamed without changes.

5_tdd_with_llms/examples/filter_and_sort_dictionaries/2c_generated_refactor_function.py renamed to 5_tdd_with_llms/examples/filter_and_sort_dictionaries_with_llm/2c_generated_refactor_function.py

File renamed without changes.

5_tdd_with_llms/examples/filter_and_sort_dictionaries/2d_manual_refactor_function.py renamed to 5_tdd_with_llms/examples/filter_and_sort_dictionaries_with_llm/2d_manual_refactor_function.py

File renamed without changes.

5_tdd_with_llms/examples/filter_and_sort_dictionaries/3_polish_implementation.py renamed to 5_tdd_with_llms/examples/filter_and_sort_dictionaries_with_llm/3_polish_implementation.py

File renamed without changes.

5_tdd_with_llms/examples/filter_and_sort_dictionaries/README.md renamed to 5_tdd_with_llms/examples/filter_and_sort_dictionaries_with_llm/README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# Filter and Sort
22

3+
> This example is from the [Workflow with LLM guide video](../../workflow_with_llm.mp4)
4+
35
Write a function that filters a list of dicts by key, and alphabetizes the
46
entries by value. The function should not modify the argument list.
57

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
""" Repeat Character
2+
3+
Write a function that takes in a string, a single character, and a number.
4+
The function returns a string with each occurrence of the character repeated n times.
5+
6+
"""
7+
8+
def repeat_character(text: str, char_to_repeat: str, repetitions: int) -> str:
9+
"""The function returns a string with each occurrence of the character repeated n times.
10+
11+
Parameters:
12+
text (str): we will repeat the character in this string
13+
char_to_repeat (str): this is the character we want to repeat
14+
repetitions (int): how many times to repeat the character
15+
16+
Returns:
17+
string: the string with a single character repeated
18+
19+
Raises:
20+
AssertionError: if the first argument is not a string
21+
AssertionError: if the second argument is not a single character
22+
AssertionError: if the third argument is not an integer
23+
AssertionError: if the third argument is less than 0
24+
25+
>>> repeat_character('Omnia', 'm', 7)
26+
'Ommmmmmmnia'
27+
28+
>>> repeat_character('Jola-Moses', 's', 2)
29+
'Jola-Mossess'
30+
31+
>>> repeat_character('Hasan', 'e', 999999999999)
32+
'Hasan'
33+
34+
>>> repeat_character('Rafaa', 'a', 3)
35+
'Raaafaaaaaa'
36+
"""
37+
38+
assert isinstance(repetitions, int), 'third argument must be an integer'
39+
assert repetitions >= 0, 'third argument cannot be less than 0'
40+
41+
repeated_text = ''
42+
43+
for char in text:
44+
if char.lower() == char_to_repeat.lower():
45+
# repeated_text += char_to_repeat * repetitions
46+
repeated_text += char * repetitions
47+
else:
48+
repeated_text += char
49+
50+
return repeated_text

0 commit comments

Comments
 (0)