Draft
Python One-Liner #1: Introduction
Loading description...
View
This comment has been reported as {{ abuseKindText }}.
Show
This comment has been hidden. You can view it now .
This comment can not be viewed.
- |
- Reply
- Edit
- View Solution
- Expand 1 Reply Expand {{ comments?.length }} replies
- Collapse
- Spoiler
- Remove
- Remove comment & replies
- Report
{{ fetchSolutionsError }}
-
-
Your rendered github-flavored markdown will appear here.
-
Label this discussion...
-
No Label
Keep the comment unlabeled if none of the below applies.
-
Issue
Use the issue label when reporting problems with the kata.
Be sure to explain the problem clearly and include the steps to reproduce. -
Suggestion
Use the suggestion label if you have feedback on how this kata can be improved.
-
Question
Use the question label if you have questions and/or need help solving the kata.
Don't forget to mention the language you're using, and mark as having spoiler if you include your solution.
-
No Label
- Cancel
Commenting is not allowed on this discussion
You cannot view this solution
There is no solution to show
Please sign in or sign up to leave a comment.
Hmm, okay. I'm going to close the one-liner series for now. I first thought that we can just rely on one's honor to actually code in one-liner, but it seems not only to depress the challenging feeling, but also to make a bad example of Kata that would require similar tasks. There MUST be a part for verifying the answer, and it seems to be complicated enough as parsing the source is obviously needed to ensure the rules.
Nonetheless, thanks for valuable feedbacks.
You don't have to change anything? :(
How does this kata decide if the solution is a one-liner? Does (or can) the author dock honor from those that do not use one-liners?
I was always wondering how do you make all your amazing one-liners. I'm glad you're going to teach us those technics!
As for the possibility of verifying if solution is indeed one-liner, I think I see one solution, but all tested items should be functions only. I use it in my Kata (http://www.codewars.com/kata/my-very-own-pythons-split-function/python) for verifying if is used generator function (as is said in description).
That's very nice way to enforce generator. I've actually failed to get through one-liner before seeing the test code. That disassembly approach was quite aggressive. I have no clue to apply similar approach to this Kata though. So far I had no luck on differentiating between regular codes and one-liner equivalents using
dis.dis()
or any otherinspect
functions.It would be best to verify somehow that the solution indeed uses one line only. Unfortunately
inspect.getsourcelines
seems prohibitted.Yeah I tried that before, but I couldn't get it to access the source.
I think I found a cheating solution for that. Well, not too nice, but might work:
CODE = '''
'''
exec CODE
CODE
can be parsed to verify the onelines.Hmm. It might work well since we can do something like:
I'll definitely try it. Thanks.
EDIT: Hmm.. It seems that it is not as simple as I thought. Additional restrictions will come up like:
CODE = r'''
, as it has different parsing rules. I'm not sure if it's free of any side-effects.'''
). Well it can be forced by using scope directive inexec
, but it is trickier than I thought.I don't exactly get your difficulties.
'''
is very nice.'''
inside their code anyway, so maybe we don't even have to mention these restrictions in the description.exec CODE
in the beginning of the tests, and then nothing else needs to be modified. Why would anyone use escaped characters in the given exercises? Also, I guess, the most common ones,\n, \s
will work anyway.CODE
and checks that the solutions are indeed one line, e.g. search for a line containingr'a_simple_function\s*=\s*lambda'
.