Skip to content
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

Open
wants to merge 1 commit into
base: devel
Choose a base branch
from
Open

Conversation

stevendes
Copy link
Owner

Completed and ready for review!

@stevendes stevendes requested a review from glpuga January 3, 2020 02:00
Copy link
Collaborator

@glpuga glpuga left a 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)
Copy link
Collaborator

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)
Copy link
Collaborator

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?

Copy link
Owner Author

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
Copy link
Collaborator

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?

Copy link
Owner Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants