• Custom User Avatar

    No, by entire array I meant that if the array has length n, his code runs through 2n elements on average.
    I presume you took the time results provided by the test cases which deviate in general, that way the claim can be made either way. If you just run both versions in a properly timed environment you get mine to be about 3x faster, regardless of whether they lists are fully randomized or worst case samples.

  • Custom User Avatar

    He traverses the entire array at most one time.

    This solution is faster than your solution: random tests in 390ms vs 450ms.

  • Custom User Avatar

    Can confirm that caps lock on european keyboard behaves like permanently pressing shift key. This means caps lock and shift key at once negate each other.

    The description should say "caps lock only matters to letters". From the tests we only know it doesn't apply to numbers but have to find out ourselves about special characters like comma or apostrophe.

  • Custom User Avatar

    I laughed too hard at this my face hurts

  • Custom User Avatar

    In short, importing the sqrt certainly doesn't benefit from being in the function. :P

  • Custom User Avatar

    Interestingly, the site groups code that imports outside the function with code that imports inside the function. Check the variations and you'll see. It just happened to choose the one with the import inside as the canonical version for some reason.

    For the most part, you are right. PEP 8 recommends only importing at the top of a file. Doing otherwise makes debugging much harder. However, technically there might be very rare situations where you might want to import inside of a function -- if only that function ever needs that module, the function is rarely or never called, and you don't want to pollute the global namespace, or if you want to defer and handle ImportError exceptions on a case-by-case basis, or you want to do some sort of conditional import depending on the passed parameters. Some others say they use it to resolve circular dependency issues, but that can almost always be avoided with a little restructuring of the affected files without the overhead a local import would involve.

  • Custom User Avatar

    you wouldn't import inside a function.

  • Custom User Avatar

    you can elaborate on that using the discussions thread instead of writing the code :D

  • Custom User Avatar
  • Custom User Avatar

    just loop over it without using a comp .-.

  • Custom User Avatar

    golfing works here but you can't use len() for every single iteration..

  • Custom User Avatar
  • Custom User Avatar

    regex and still chaotic, ugh.

  • Custom User Avatar

    cheat :P

  • Custom User Avatar

    This comment is hidden because it contains spoiler information about the solution

  • Loading more items...