Ad
  • Custom User Avatar

    For simplicity only. In real use it is obvious to use .lower() method. Even additional checks for digits and special charasters.

  • Default User Avatar

    is there a reason why you didn't use .lower() function ?

  • Custom User Avatar

    it's O(n) too (with n the length of the sliced section)

  • Custom User Avatar
  • Custom User Avatar

    to avoid problem in first case the simplest way is make copy argument??

  • Custom User Avatar

    Thank you for taking the time to answer my questions!

  • Default User Avatar
    1. The problem about mutating the list is that if the same instance of the list is used outside of the function, the other function will see the modified list. That can generate strange and unpredictable behavior outside of the present function. Said like that, you could not see the problem... So let me give you a concrete (it happened to me! ;) ) example: 5 kyu, I was working on a kata, and I was mutating the list. All worked fine with the fixed tests, but in the random tests, that went realy wrong. After the execution of my function, the list was empty. And after this execution, the code was executing the reference solution, using the same list object (same instance, so). And that list being empty....... You see what I mean. ;) So, to avoid unpredictible troubles, it's good practice to avoid mutations of arguments when possible. Work with a copy, mutate the copy (for example)

    2. "O(N)" talks about the "time complexity" of the algorithm. It would be too complicate to really elaborate here if you do not know the concept. You can google it, you should find easily things about that. The general idea is that, when you have 1 loop, you have O(N), if you have a loop inside that first loop, it's O(N^2), ... (simple example, it might be far more complicate than that). And sometimes, the inner loop is hidden by another function. Here, by removing an element in the middle of the list, python has to move all the next elements one step backward. Here is the inner (hidden) loop that makes this solution O(N^2).

    Cheers

  • Custom User Avatar

    Could you explain what you said further?
    I'm not familiar with 'mutates the argument', and your second bullet escapes me completely.

  • Default User Avatar

    This solution is actually very BAD practice!

    You shouldn't delete elements of your array:

    • first, it mutates the argument (bad practice)
    • second, deletion in a list is O(N) by itself so it makes your solution unefficient.
  • Custom User Avatar

    Very well done. I tried to use for loops to my detriment. I'll have to keep this in mind for similar problems.

  • Default User Avatar

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