Ad
  • Custom User Avatar

    Ranked 6 now. Too high for that also.

  • Custom User Avatar

    spoiler flag, damn you! x/

  • Custom User Avatar

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

  • Custom User Avatar

    Definitely overranked, but it can't be changed anymore.

  • Default User Avatar

    I'm not sure what are the criteria for ranking katas, but I feel this should not be ranked 5kyu. Please, don't bother, just my feeling.

  • Default User Avatar

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

  • Default User Avatar

    OK. But, perhaps you should admit that your code returns "YES" when an empty list is given. And perhaps it's no a coincidence.

    No, regarding the expression "guarded by an assert" I mean this construction:

       def f( people ):
          assert people != [], "Error, empty list"
          do_what_ever_with_non_empty_list
    

    Better than a try-except for checking parameters validity at the very beginning.

    Again, please, no harm intended.

    BTW, how is it that you post a link to a solution within these "discourse cells"? You told me that is better than refering to the authors, and I agree. But I don't see how to do it. At least, not at first sight.

  • Default User Avatar

    Hi,

    if nums.count(0) > 1: is my mistake. In my solution, I reuse the zeros.

    filter(None, iterable) is an idiomatic use described in the Python documentation (see here).

    @FArekkusu:(foo(x) for x in arr) is a generator expression and it returns a generator too.

    Regards,

    suic

  • Custom User Avatar

    My code looks like the way it does because it's easier and shorter to write.

    Were it not a proper input, I guess that it should be guarded by an assert

    What?..

    that's the boilerplate that so many Pythonist just hate

    It's always a good practice to use try-except block if you know what you're doing -_-

  • Custom User Avatar

    It could easily be worse than O(4n) because you're searching for 0's index inside your list comprehension. Twice.

    Your speech about Python's functional language features are wrong. Python is not functional because lambda's are restricted to one-line functions. Moreover, map lets you apply a pre-defined function to the array elements using a very concise syntax - map(foo, arr) instead of (foo(x) for x in arr), and it also returns a generator instead of the whole list which is a big advantage when you can't waste memory. The same applies to filter.

    And again you don't know when it's better to use filter. For simple situations list comprehensions are a lot better choice.

    And regarding being pythonic - the truly pythonic code is [x for x in arr if x] (or alternatively filter(lambda x: x, arr)).

  • Default User Avatar

    Thank you for your advice.

    Regarding the comments of the code, some user (Firefly2002) actually commented that he liked the comments. I'd not have commented so profusely though if it were not because of the restriction over the complexity of the solution. By the way, you're right, it's not O(2n) but O(4n). I realized of the mistake after publishing the solution, but I forgot to update the comments (actually, as you can see there is a dangling comment that says "Also, since". My fault.

    The fact that the solution is not pythonic... you're right. nums.count(0) is definitely better that the awfull list comprehension that I wrote... and most pythonist look down on map (that's why Python is not and won't ever be a proper functional language). But, correct me if I'm wrong, I'd say that filter(None, nums) is not very pythonic either. I mean, may be that it does what is pretended (to strip all zeroes from nums), but it does so through a very obscure syntax that seems to aim something just the opposite of what it's done. I'd rather use: filter(( lambda x: x!=0 ), nums) or even [x for x in nums if x != 0] (probably this latter is the most pythonic of them all). Both are cleaner (though a bit more verbose).

    Regarding the use of // instead of /, I actually though of using it, but since product has all the elements in nums but the zeroes... I guess that the result should be the same. And bad if it's not.

    Also, I'd say that the second call to nums.count(0) (in if nums.count(0) > 1:) could be rewritten just as if zeros > 1:. Actually a tiny improvement that avoids a second iteration through nums.

    Nevertheless, of course your solution is far better than mine. Perhaps that's why you're 1 kyu and I'm only level six. Still learning ;-)

  • Default User Avatar

    Don't assume stuff out of nowhere. I haven't said anywhere which option I prefer. In fact, I prefer neither one as an empty array would be an incorrect input.

    Please, take it easy. I'm not here to quarrel over anything. I'm here to improve my coder's skills, to learn and, whenever I can, to give advise to less experienced coders. I though that the "War" part of the name of this site was a mere literary figure, but I can see that it's one of the features of the site ;-)

    If I said that "you" though that the answer to tickets([]) == "YES" is because your solution behave that way. As most published solutions do. I didn't pretend to read your thoughs or your preferences.

    Whether an empty list is a valid input or not... well, I've checked the Kata constraints and, up to my understanding, they don't say anywhere that the empty list is not a valid input. Actually, most people's solutions treat the empty list as a proper input. Were it not a proper input, I guess that it should be guarded by an assert (yes, I know, I know: that's the boilerplate that so many Pythonist just hate).

    You should post a link to the solution. No sane person will spend their time scrolling through thousands of code snippets to see that there're wrong solutions which do not work properly.

    Yes. I'm new to the platform and I don't know how to use it propery yet. I didn't know how to place a link into a "discourse" item. Perhaps you could me say how. I'd be most grateful :-)

  • Custom User Avatar

    You yourself think that way.

    Don't assume stuff out of nowhere. I haven't said anywhere which option I prefer. In fact, I prefer neither one as an empty array would be an incorrect input.

    Some solutions posted and acepted as right are actually wrong because of this (ie. Wangsihe, Hickock)

    You should post a link to the solution. No sane person will spend their time scrolling through thousands of code snippets to see that there're wrong solutions which do not work properly.

  • Custom User Avatar

    Very nice comments! Always helpful for new coders :)

  • Default User Avatar

    It makes every sense if there is not any restriction on an empty list of people (a "huge" empty list of people, though :).

    Some of the programs posted just break if you feed an empty list (for example, timakz11 and hainihao's ones). That's plain wrong.

    Now, another issue is which should be the correct answer on such a situation (empty lists): "YES" or "NO".

    Most people who have posted a solution think that the solution is "YES". You yourself think that way.

    Some few return "NO" when the empty list is there (technout and kill-that-Hohhot-man to name just two).

    I'd say that the "technically" right result (that is the "YES" answer) is the correct one. At least this is what most people think.

  • Loading more items...