Ad
  • Custom User Avatar

    Ah you are absolutely right. Didn't think of the visibility of the solution.

  • Custom User Avatar

    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...)

  • Custom User Avatar

    You used my previous solution ;)

  • Custom User Avatar

    0 is False and 1 is True

  • Custom User Avatar

    do you want it to return 0 when not even, and 1 when even?

  • Custom User Avatar

    def dude():
    return "Where is your PEP?"

    print(dude())

  • Custom User Avatar

    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!

  • Custom User Avatar

    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.

  • Custom User Avatar

    Damn i always forget to use the return of the sorted method, thanks for the tip :)

  • Custom User Avatar

    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)))

    And it's also sorting less element

  • Custom User Avatar

    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.

  • Custom User Avatar

    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.

  • Custom User Avatar

    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.

  • Custom User Avatar

    Partial goal of the solution is to use no modules

  • Custom User Avatar

    According to PEP 8, Programming Recommendations:

    Always use a def statement instead of an assignment statement that binds a lambda expression directly to an identifier:

    # Correct:
    def f(x): return 2*x
    
    # Wrong:
    f = lambda x: 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)

  • Loading more items...