-
Notifications
You must be signed in to change notification settings - Fork 0
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
Completed the about_iteration koan #17
base: devel
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good work, a couple of questions!
@@ -14,20 +14,20 @@ def test_iterators_are_a_type(self): | |||
for num in it: | |||
fib += num | |||
|
|||
self.assertEqual(__, fib) | |||
self.assertEqual(15, fib) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Weird, but the name of the variable suggests a Fibonacci sum, but the algorithm is just the addition of the numbers xD.
@@ -47,7 +47,7 @@ def is_even(item): | |||
seq = [1, 2, 3, 4, 5, 6] | |||
|
|||
even_numbers = filter(is_even, seq) | |||
self.assertEqual(__, even_numbers) | |||
self.assertEqual([2, 4, 6], even_numbers) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In your words, what's the difference between filter
and map
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
map
applies the function in all members of the iterator, in contrast, filter
do a comparison with the members and if that result is true, it's part of the final output.
|
||
# Extra Credit: | ||
# Describe in your own words what reduce does. | ||
|
||
|
||
# Apply the function to every member of the list, the final return is what the final iteration of the function outputs |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, but it's a bit more specific than that, right? how does it differ from map
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The way in which reduce
works and differs from is that it receives a function and a sequence(just as map) but it returns just a single value.
The way that this value is calculated is by taking the first two members of the sequence
and then executing the function, after that, the result of that first execution is used with the next value of the sequence, this process gets repeated until the last member of the sequence is taken to account.
Completed and ready for review!