-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Add list-ops problem #170
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
Add list-ops problem #170
Conversation
Congrats on your first PR, Jacqueline! That's a pretty cool exercise but it contains a few issues that should be fixed before it can be merged.
I'll add a few more points as inline comments on the commited files. |
@@ -0,0 +1,27 @@ | |||
|
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.
It's only cosmetic but can you remove that line?
Thanks for all the helpful feedback. I will implement the changes you mentioned. |
I'm re-writing the tests for map() and am wondering what is the most efficient way to assert that a unit test returns a generator expression. Is there any way to compare two generator expressions without converting them both to lists or tuples? |
The Python3
While it can be done I somehow feel that it would be somewhat "unpythonic". It would certainly be in conflict with the concept of duck-typing. One idea would be leave this test to the nitpicking community. Another one may be to have a test that can only be practically passed with an implementation that returns a generator. For example ask for the sum for a large range of numbers or something like that.
Yes. |
Thanks for responding. I agree that checking if a unit test returns a generator is unpythonic(/too Java-like...) I think your idea of a test that can only be passed with an implementation that returns a generator is a good one and I will try that out. That is also consistent with the idea of updating all three functions so that they accept various iterables. |
Hi @outkaj, Are you still working on this exercise? Do you need any help? |
It is discussed right now to deprecate the So @outkaj is there anything I can do to help you finish this? |
Thank you both for checking in & sorry for the radio silence. I disappeared into other languages and projects, but will take a look at this right now and send a PR ASAP! |
In other languages implementing this problem, I see additional functions such as filter, fold, append, reverse, and concatenate. I'd like to add them as well, since otherwise the Python equivalent of this exercise will be significantly easier by comparison. What do you think? |
Good point! I would even go that far and split data = [1, 2, 3, 4, 5]
assert foldl(div, data, 1) == 0
assert foldr(div, data, 1) == 1
assert foldl(sub, data, 0) == -15
assert foldr(sub, data, 0) == 3
assert flat([[[1,2],[3]],[[4]]]) == [1, 2, 3, 4] |
I just committed the updated version to my fork. Let me know how it looks and I can make the necessary changes before updating the PR. Relevant notes: |
Some quick notes, will have a closer look later. Yes we use I'm not sure if and how we should rename the bult-in functions list-ops/example.py Line 6-10: def length(xs):
return sum(1 for x in xs) Line 40: list-ops/list_ops_test.py Line 42-43: I'm not sure about the reverse empty test. I would assume Line 55, 57, 60, etc: you don't need lambda to pass a function as parameter self.assertEqual(21, foldl((lambda x, y: operator.add(x, y)), [1, 2, 3, 4, 5, 6], 0)) self.assertEqual(21, foldl(operator.add, [1, 2, 3, 4, 5, 6], 0)) |
I would recommend re-naming filter and map. The original filter_src and map_src are too awkward, but how about filter_clone and map_clone? |
(I can squash the commits to just one reading "Add list-ops problem" once it's ready). |
Finishes the abandoned pr #170
I did not add the exercise to the config.json yet because I was not sure where it should be included in the order of problems.
This is my first time doing a pull request so please let me know if there are any issues.