Whew.. passed all tests except one for a long time. Found out that I altered the change for this test in another place than where I altered the changes for the rest. Shoot me. This was a really interersting kata though, thanks!
I don't know if it´s intended, but a function wrote in one single line is extremely difficult to read and understand what it is doing, mainly because of all the if-elses.
A tip: you could just replace list with sorted to make it shorter sort = lambda x: ''.join(sorted(filter(str.isalpha, x)) + sorted(filter(str.isdigit, x)))
If performance is a concern, it's still better to write the 'yield' expression. These are lazy gens and they're sometimes half as slow, but it's likely just splitting hairs unless you're working on exceptionally large sets of data.
Actually, generally accepted best practice is to not use named lambdas. Lambdas should be 'throw away' expressions, not statements and def fn's will usually eek out performance over λ expressions but not by anything really noticeable unless you have some order of op stuff going on. If you really want to make this fn sing, use a generator, ala my fork.
using a lambda, an "anonymous function" to make a named function is sooOoOOoOOooOooOooOo smart and definitely not bad practices. Most linters will yell at you for this.
Always use a def statement instead of an assignment statement that binds a lambda expression directly to an identifier:
# Correct:deff(x): return2*x
# Wrong:f=lambdax: 2*x
The first form means that the name of the resulting function object is specifically 'f' instead of the generic '<lambda>'. This is more useful for tracebacks and string representations in general. The use of the assignment statement eliminates the sole benefit a lambda expression can offer over an explicit def statement (i.e. that it can be embedded inside a larger expression)
Ah you are absolutely right. Didn't think of the visibility of the solution.
next time, don't post the solution of the hard version in the easy one, thx.
(look at the top of this solution, if you don't understand why...)
You used my previous solution ;)
0 is False and 1 is True
do you want it to return 0 when not even, and 1 when even?
def dude():
return "Where is your PEP?"
print(dude())
Whew.. passed all tests except one for a long time. Found out that I altered the change for this test in another place than where I altered the changes for the rest. Shoot me. This was a really interersting kata though, thanks!
Hello,
I don't know if it´s intended, but a function wrote in one single line is extremely difficult to read and understand what it is doing, mainly because of all the if-elses.
Damn i always forget to use the return of the sorted method, thanks for the tip :)
A tip: you could just replace
list
withsorted
to make it shortersort = lambda x: ''.join(sorted(filter(str.isalpha, x)) + sorted(filter(str.isdigit, x)))
And it's also sorting less element
If performance is a concern, it's still better to write the 'yield' expression. These are lazy gens and they're sometimes half as slow, but it's likely just splitting hairs unless you're working on exceptionally large sets of data.
Actually, generally accepted best practice is to not use named lambdas. Lambdas should be 'throw away' expressions, not statements and
def
fn's will usually eek out performance over λ expressions but not by anything really noticeable unless you have some order of op stuff going on. If you really want to make this fn sing, use a generator, ala my fork.using a lambda, an "anonymous function" to make a named function is sooOoOOoOOooOooOooOo smart and definitely not bad practices. Most linters will yell at you for this.
Partial goal of the solution is to use no modules
According to PEP 8, Programming Recommendations:
Loading more items...