7 kyu

Sorting Dictionaries

3,548 of 5,322cmgerber
Description
Loading description...
Sorting
Lists
Fundamentals
  • Please sign in or sign up to leave a comment.
  • avermakov Avatar

    I think it would be nice to add cleaner differentiation between keys and values.

    If you look at example/sample below, it does not really add much to the description. What goes first, key or value? What do we sort by? You can answer these questions by reading the description, but this defeats the purpose of example.

    sort_dict({3:1, 2:2, 1:3}) == [(1,3), (2,2), (3,1)]
    

    I think something like this would be a lot easier to read and actually complement the text:

    sort_dict({'a': 1, 'b': 3, 'c': 2}) == [('b', 3), ('c', 2), ('a', 1)]
    
  • saudiGuy Avatar

    python new test framework + random tests are required. updated in this fork

  • trashy_incel Avatar

    javascript should have tests with strings as values, many solutions are only handling number comparison

  • yLaWy Avatar

    This comment has been hidden.

  • JohanWiltink Avatar
  • megawatt Avatar

    This should be 6 or 5 kyu, this one is difficult to solve 😨

  • donaldsebleung Avatar

    Javascript version of Kata could do with random test cases as well as fixed ones; keep that in mind when authoring future Kata :)

  • Creative Chaos Avatar

    This comment has been hidden.

  • bzang Avatar

    This comment has been hidden.

  • wthit56 Avatar

    I enjoyed this kata; it's an interesting problem, so well done on that. The description was a little sparse, however, with some of the more nuanced edge-cases not mentioned anywhere:

    • Keys: Instead of the keys being just left as strings, they need to be converted into numbers, if able. This is implied, but the rules on what should be converted aren't specified.
    • Order: You should specify that the order must remain intact where values are the same.

    These were a little counter-intuitive (at least for me), so having them explicitly said up-front will save people a lot of headscratching and guesswork ;P

  • computerguy103 Avatar

    Keys in Javascript are always strings, not numbers. In light of this, I'm going to argue that requiring numbers in the output is wrong. They should be strings.

    dict[1] and dict["1"] are the exact same thing, because 1 has to be implicitly cast into a string before it can be used as an array index. That's also why JS doesn't automatically take the nearest integer or floor when you write dict[1.5] - 1.5 is cast into a string, and any string is a valid key; it's dict["1.5"].

  • mortonfox Avatar

    I think the kata description should specify that the sort needs to be stable. This comes up in the Haskell random tests when some of the values are equal and if I use reverse instead of changing the comparison function.

  • jshilkaitis Avatar

    This is a solid Python kata, but the Javascript version distracts from the point because the programmer has to hack around Javascript's conversion of number keys into string keys (as mentioned by OverZealous).

  • marutiborker Avatar

    I am getting an error "str$ is not defined" when I am trying sample testcases in js

  • ZozoFouchtra Avatar

    JS-translation kumited ( 4 weeks ago )

  • user710937 Avatar

    One test in the "coding view" is done twice.

  • turnkey Avatar

    Typo in description (larges => largest).

  • grant-musick Avatar

    It could use a couple more tests as examples. In particular, something with less symmetric order to make it clear what is the desired output.

  • girlPC Avatar

    This comment has been hidden.

  • mdshw5 Avatar

    You should name the argument something other than "dict" since "dict" is a builtin.