6 kyu
Convert Lambda To Def
Loading description...
Fundamentals
Strings
Regular Expressions
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.
The link at the end of the description links to a draft kata, and should be removed.
Either all inputs must be single-parameter lambdas, or random tests must also check multiple-parameter lambdas - you're not supposed to introduce different requirements only because you can't write tests for something.
ok done. i removed double parameters.
Lambdas are "supposed to have a single parameter", but there're lambdas with multiple parameters in the fixed tests. This part of the specifications is also not mentioned anywhere.
ok done! Specified in description.
No tests with variable number of spaces/no information that these won't be tested.
specified in description
No tests with
*args
,**kwargs
, positional-only arguments, keyword-only arguments/no information that these won't be tested.specified in description
No tests with zero arguments/no information that this won't be tested.
specified in description
Random tests always generate lambdas with a single parameter.
it's supposed to be like that.
Some spaces at the end in the test cases are inconsistent.
'def rgXbAr(Pn):\n return Pn * 1' should equal 'def rgXbAr(Pn):\n return Pn * 1 '
due to that space at the end. I would recommend stripping the text and then asserting.oh. Could you help me with this? I don't know where this would have occured.
ok, i think it's good now.
The description still has almost no specifications about what and how has to be done.
alright, can you give me examples of what i need to change?
You don't know what "specifications" means? You how to provide a complete explanation of the input format, the output format, and any special rules/requirements/limitations. As it currently stands, your description is not even correct because anonymous functions don't have names.
ok i will do that. But i can't right now. Codewars seems to have a problem.
alright, i think that's all description i can give. I'm pretty sure people understand very clearly. If you still think this is a problem, give me specific changes to make, meaning:
change this:
blah bah blah
in your description tobl bla bl
like that.
Could you explain how the only thing that you've added - a statement that we are supposed to "return a function with the same function", which makes absolutely no sense, corresponds to my previous message that the description should provide "a complete explanation of the input format, the output format, and any special rules/requirements/limitations"?
If you have zero understanding how to properly author a kata, just don't do that. You took someone else's reference solution because you couldn't solve your own task, and now you're asking other people to also write a description and tests for you because you can't do these either - the only thing you did is come up with an idea, and that's really bad.
no, you've got it wrong. No one complains about the description. IT seems fine. But if you have a problem, you need to tell me specific changes. Like the example above. And for the bottom paragraph, i already explained.
Function names and parameter names never include digits.
also, i'm trying to add numbers, but when i click re-publish on my kata, it says server timed out. I think codewars has a problem right now. I will do it when it's fixed.
ok, done. I included digits too.
Tests should generate function names and parameter names that are valid identifiers, not just sequences of lowercase letters.
do you mean with special characters, and uppercase letters?
[a-zA-Z_]\w*
so i should include this in the testcases?
no, that's the rule for valid identifier, so you can build a function returning somehting built along that line
ok, i'll try that.
@FArekkusu, ok, i did it.
Random tests always generate lambdas with a single parameter.
yes, i meant to do that.
Is there a rule somewhat that the function will always have exactly 1 parameter, or you just wrote such generator and decided that it's "good enough"? Either your fixed tests break this rule, or you're wrong and it's definitely not "good enough".
what? For few fixed tests, i did more than one variables, but for random, it's just one.
no, use random number of arguments, plz
edit: randomizing a bit the number of spaces around the commas would be good too. But then you have to specify exactly how to format multiple arguments in the output
@Blind4Basics, oh. Yes, i got that, but i don't really know how to do the testcases for that. Is it ok if i do random number of arguments, but don't use all of them in the return part?
But if you could do the random number of testcases part, or explain it to me, i would appreciate it. Thanks!
yeah, could be. Or sum stuff like
max(first ahlf of args) + min(second half)
, for examplecould you explain that a bit more?
build a list of identifiers of random length (at least 2 for something like the above), compute middle index, then
f"max({ ','.join(args[:haldIdx]) })) + min({ ','.join(args[haldIdx:]) }))"
, or use a random operator in the middle or whatever you think about that is valid codeoh, btw, you have to say in the description if varags and kwargs will be used or not. Same for default arguments.
this might help: https://docs.codewars.com/languages/python/authoring/
i still don't get it. Could you do it instead. If you want to i mean. Thanks in advance!
@Blind4Basics, could you edit the testcases please? I'm not how this works.
.
An example is not a specification.
no, i meant, that was an example
And I meant that the description must have a set of specifications, so that you don't have to look at an example to understand what the task is.
ok, could you tell me what to change?
the description does explain it. The examples are just to show how the process will work for testing.
After about 50 resubmits I got it XD
haha nice. But could you help me with the issues? Thanks!
Yeah I'll take a look.
I was lucky, only took me like 5!
Thanks a lot! Please let me know when you are done.
@Fbasham, hi, are you done? Please let me know if you are. Thanks!
hi, could you let me know when you are done? Thanks!
I think this would be more interesting if you force the answer to be very robust. Randomize the number of spaces between things, add lambdas inside the lambdas, check edge cases where the name of the function is something like
lambda_f
, etc. Just my opinion though.thanks, but could you help me out with your issue? I don't what's causing that.
There are bugs. Sometimes
return
is neglected from the expected random tests. Sometimesdef
is missing characters.Oh. Could you help me with this? I don't know what's causing the mistakes sometimes.
"def fdi(de):\n return de.split(':')" should equal "f fdi(de) de: de.split(':')"
That certainly isn't correct.Also, occasionally there are extra spaces in the function body, which your solution seems to want us to remove, but nothing is mentioned of that in the description.
could you help me with this? I don't know what's causing it.
I think it would help if you wrote out your reference solution in a readable way. One liners are fun, but the reference solution should be a clean, good-practice way to solve the problem. Not to mention that trying to debug it is somewhat challenging.
ok, thanks for the suggestion. Do you think i should change it? Is it causing any problems? Or i can just keep this in mind for next time. What do you think?
Yeah I definitely agree with @Kacarott. The reference solution is a doozy to read/debug. Keep in mind @The-Kingfisher, your solution is always going to pass the tests becasue you wrote it and we're testing against you. I'd rewrite the reference solution.
Well there is clearly still bugs, unless you already solved those? I think you should change it now, and it might help you figure out what is causing the bugs. You shouldn't just wait for Fbasham to do it for you.
ok. Can i take your solution for the reference solution?
Mine is just another one liner.
You should just use the one you have but break it into readable stepsOr actually, just write it from scratch. That's what this whole kata is about right? ;)my solution can't actually be in multiple lines easily. Since if i do replacing on one line, it updates to the return part. So they need to be in one line. Do you have any alternates?
@The-Kingfisher
I'm done looking. I'd recommend doing what @Kacarott suggests. In otherwords, the reference needs to be rewritten. Your input generation looks consistent though, which is good.
This comment has been hidden.
@Fbashman, can i?
The reference solution is the one used to validate the tests (it has its own box in the kata editor). However you would use the same one in
test_random_convert_lambda_to_def
to generate the answer.I just want to point out, that if you take someone elses solution in order to make your kata work, it essentially means that you are unable to solve your own kata...
I wouldn't recommend using somebody else's solution, but I can't stop you either way XD
@Kacarott, no i meant, just to get it done quickly. Meaning, to make another would take some time. And i can't reuse my old one either, so the easier is to just take someone's with permission.
@Fabasham, um, so would you allow me? for yours i mean.
Also, please read my comment above.
This comment has been hidden.
ok, thanks!
i think the issue is resolved now.
Took me 3 tries to figure out you want us to left trim the function body, but leave trailing white space as is. Also PEP-8 man, PEP-8!
oh haha. Also what do you mean by
PEP 8
?PEP-8