-
Notifications
You must be signed in to change notification settings - Fork 3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Lecture "Brute-force algorithms", exercise 3 #18
Comments
def my_enumerate(input_list):
output_enumerate_object = []
for index in range(len(input_list)):
tuple = (index, input_list[index])
output_enumerate_object.append(tuple)
return output_enumerate_object
def test_my_enumerate(input_list, expected):
result = my_enumerate(input_list)
if result == expected:
return True
else:
return False
print(test_my_enumerate(["Remember", "the", "fifth", "of", "November"], [(0, 'Remember'), (1, 'the'), (2, 'fifth'), (3, 'of'), (4, 'November')]))
# It prints True |
def my_enumerate(input_list):
input_length = len(input_list)
output = [(index, input_list[index]) for index in range(input_length)]
return output
def test_my_enumerate(input, expected)
return my_enumerate(input) == expected
volumes = ['Preludes and Nocturnes', 'The Dolls House', 'Dream Country', 'Season of Mists', 'A Game of You', 'Fables and Reflections', 'Brief Lives', 'Worlds End', 'The Kindly Ones', 'The Wake']
print(test_my_enumerate(volumes, [(0, 'Preludes and Nocturnes'), (1, 'The Dolls House'), (2, 'Dream Country'), (3, 'Season of Mists'), (4, 'A Game of You'), (5, 'Fables and Reflections'), (6, 'Brief Lives'), (7, 'Worlds End'), (8, 'The Kindly Ones'), (9, 'The Wake')])) |
Hi all, please find attached my personal solution – also available online:
An important point: the rationale of using TDD to test the code is that all the tests must be passed (and this, somehow, guarantees the correctness of the code). If a test is not passed, it means that there is something wrong in the code. Thus, please, avoid using tests that fail on purpose since this does not demonstrate the correctness of your code. |
def my_enumerate(input_list): print(my_enumerate([1, 2, 3, 4])==list(enumerate([1, 2, 3, 4]))) |
Write in Python the function
def my_enumerate(input_list)
which behaves like the built-in functionenumerate()
introduced in Section "Linear search" and returns a proper list, and accompany the function with the related test case. It is not possible to use the built-in functionenumerate()
in the implementation.The text was updated successfully, but these errors were encountered: