Ad
  • Custom User Avatar

    but for some reason everyone votes as usual )

  • Custom User Avatar
  • Custom User Avatar

    In python, conditional and Boolean expressions contain empty objects(0, None, ", [], {} ...) are treated as False, not empty(1, [1, 2] , {34, 45}, ' qwerty', print, int) as True. But it is important to remember that they are not equal! That is, 1 == True, but 1 is not True. For example: if 3+5: print('hi') here 3+5 is not an empty object that is perceived as True in the context of a conditional expression. But at the same time (3 + 5 ) != True.
    Now about the main thing. Logical operations in python use so-called Lazy Evaluation. This means that in an expression for example: (False and True) values are calculated in order from left to right, but and gives True only if both(all) operands are True, that is, as soon as python gets False in an expression with AND, it knows that the truth will not work and immediately returns this value. An expression with OR gives True if at least one operand is True, that is, it will return the first one that comes along, but if it does not find it, it will return the last one.
    Here I hope I pushed you on the right path and didn 't confuse you too much : D

  • Custom User Avatar

    Yes! now it works thanks! The funny thing is that I thought to press reset myself, but I didn't do it for something I wrote here... it 's even a shame ) conclusion - you should not rush haha

  • Custom User Avatar

    I think it is not necessary to prove that the task is simple, but:
    Traceback (most recent call last):
    File "main.py", line 2, in
    import codewars_test as test
    ModuleNotFoundError: No module named 'codewars_test'

    please fix it)

  • Custom User Avatar

    Copy/paste from Details )

  • Custom User Avatar

    I wanted to make the same assignment in the first line of the code, but I got an error because I did not put parentheses in tuples.
    Dude, this is really elegant! Thanks to you, I've learned a lot about ternary operators and unpacking tuples in them !
    Thank you!

  • Custom User Avatar

    Really cool ! My solution is very cumbersome :( I hope with experience it will come!

  • Custom User Avatar

    Why does my solution with a while loop give a result for 100 digit numbers in less than a second and this is in the debugger in the browser! And here is a time error!?

  • Custom User Avatar

    thank you, i'll definitely read.

  • Custom User Avatar

    can anyone explain how * works in this case?

  • Custom User Avatar

    That's right, this problem of the system as a whole and the principle of 8ku tasks can also be confusing and this problem could have been 8ku! That's the problem! You're right, maybe the authors aren't to blame here. Again, I liked the task itself!

  • Custom User Avatar

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

  • Custom User Avatar

    the problem would be 8 ky if the description was clearer) My solution is not perfect, but this is because when solving the problem I thought about 'html' and some other garbage. If in fact it is just taking an element from the list by a numeric value and multiplying the string '
    ' Apparently this is the meaning of programming - to find a simple meaning in moronic conditions.

  • Custom User Avatar

    The first square brackets contain a list of values to be returned. The second square brackets contain an expression whose calculation results in a slice for the first list. bin_str. count ("1")%2 means that we calculate the number of occurrences of' 1 ' in bin_str and check whether the number of units is even. (parity = = "even") will give 1 or 0 depending on whether an even number of units is expected or an odd one. in essence, it looks something like this:

    imagine that bin_str is equal to '010101' and parity is equal to 'even'
    [0, 1][bin_str.count("1") % 2 == (parity == "even")] = [0, 1][3 % 2 == (parity == "even")] = [0, 1][3 % 2 == (1)] = [0, 1][1 == (1)] = [0, 1][1] = 1
    Here it is necessary to understand that when comparing (==) two operands, it turns out True if they are equal and False if they are not equal. True is the same as 1 False is the same as 0. True = 1, False = 0. True+True = 2, False + False = 0, ... I hope it helped somehow, if something is wrong experienced wars will correct.

  • Loading more items...