6 kyu

Grouping integers into a nested list

458 of 631the_Hamster
Description
Loading description...
Fundamentals
Algorithms
  • Please sign in or sign up to leave a comment.
  • ndegz Avatar

    Good one!

  • KayleighWasTaken Avatar
  • JohanWiltink Avatar

    the goal is to sort the numbers IN PLACE

    No, it is to group the numbers. Sorting in place is something entirely different.

  • JohanWiltink Avatar

    the key will always be positive

    Not even the description examples stick to this, and the example and fixed tests don't either. ( I don't understand at all why this was even specified. )

    This should at least be changed to "non-negative", or preferably could be abandoned altogether.

  • JohanWiltink Avatar

    JavaScript translation

  • JohanWiltink Avatar

    Haskell translation

  • Cloud Walker Avatar

    This comment has been hidden.

  • saudiGuy Avatar

    python new test framework is required. updated in this fork

  • rowcased Avatar

    Typos in description:

    • ...the order in with the numbers appear (with should be which)
    • ...belong in a seperate group (seperate should be separate)
    • ...numbers form seperate groups (seperate should be separate)
  • DallogFheir Avatar

    How can you sort them in place if you need to create new lists?

  • zebulan Avatar

    @the_Hamster,

    • PEP8: Function Names

      Function names should be lowercase, with words separated by underscores as necessary to improve readability.

      mixedCase is allowed only in contexts where that's already the prevailing style (e.g. threading.py), to retain backwards compatibility.

      groupInts -> group_ints


    Your example test cases seem over-complicated and inconsistent. You are creating lists of actual and expected values, assigning them names, creating another list of all of the tests, iterating over them and then unpacking them into assert_equals calls. After all of that, you then put two more test cases in the proper format below the loop.

    Why not just skip all that and go to the assert_equals calls directly (as the Codewars Python docs show)?

    Also, the spacing inside of each 'test' list is giving PEP8 warnings using PyCharm:

    * PEP8: whitespace after '['
    * PEP8: whitespace before ']'
    

    You could simply rewrite the Example Test Cases like this:

    test.it('Example Test Cases...')
    test.assert_equals(groupInts([], 0), [])
    test.assert_equals(groupInts([1], 1), [[1]])
    test.assert_equals(groupInts([1, 2, 3], 0), [[1, 2, 3]])
    test.assert_equals(groupInts([1, 2, 3], 3), [[1, 2], [3]])
    test.assert_equals(groupInts(
        [-1, -1, -1, 10, 10, 10, -1, -1, -1, 10, -1, 10], 10),
        [[-1, -1, -1], [10, 10, 10], [-1, -1, -1], [10], [-1], [10]])
    test.assert_equals(groupInts([1, 1, 1, 0, 0, 6, 10, 5, 10], 6),
                       [[1, 1, 1, 0, 0], [6, 10], [5], [10]])
    

    Simple fix to go from 16 lines to 10 (you could get it down to 7 lines total if you don't care about line lengths exceeding 80 characters). Easy to read, no need to name variables and it stays consistent with almost every other Python katas Example Test Case style.

    Thanks!