Beta

Flatten A Nested Dictionary That Contains Lists

Description
Loading description...
Recursion
Algorithms
  • Please sign in or sign up to leave a comment.
  • user9359099 Avatar

    Challenging! Especially the possibility of a key's being int or string makes it even more compelling. Nice kata.

  • lechevalier Avatar

    Lack of small preloaded tests, especially tests on arrays.
    Debugging huge random tests is quite a pain.

  • Blind4Basics Avatar

    what about the possibility of having a list as first layer? (note: it would need a slight change in the description)

  • Blind4Basics Avatar
    {..., '2': []} should equal {..., 2: []}
    

    This behavior isn't specified in the description (and is highly arguable): the original key was an int, but it hasn't been converted to a string in your solution. For now it's undescribed, but moreover, that sounds inconsistent to me (because if the first key is an int and you find another layer below, it will be cconverted to a string. So for homogeneity purpose, all keys in the output should be strings).

    Side note: currently, the way the test suite is splitted (is it even splited..?) isn't correct: everything appears in a "random tests" block. => ?
    Some readings you might find useful: https://github.com/Codewars/codewars.com/wiki/Codewars-Python-Test-Framework-V2

  • Blind4Basics Avatar

    Hi,

    Unfortunately, that's a duplicate of an old kata (which is JS only, that's why you didn't find it... if you searched for duplicates... x) ). Moreover, it would need:

    • random tests
    • tests with keys longer than 1 char (not really important, but...)
    • what about empty dicts or empty lists on the way? => the description is missing the info that it won't happen or those become values of the final dict and the edge case is missing

    Because of the "duplicate" problem, you should unpublish yours. You can still train your authoring with it, but don't expect it to be approved. The better way would be to translate the other one (tho, that woul dneed to handle some things in there: iirc that kata has some issues)

    cheers.

    • Voile Avatar

      Where is the link to the duplicate though? ;-)

    • Blind4Basics Avatar

      mmm... Seems like the one I was thnking about w as actually doing the opposite operation. So, the duplicate aspect isn't a problem (or there are others I don't know about), but the other points still stand.

    • Unnamed Avatar

      This is the closest I can find: https://www.codewars.com/kata/lets-flat-them-out It doesn't have lists.

    • daniloxxv Avatar

      I believe this would be a duplicate (including the list aspect, although they are handled in a slightly different way).

      https://www.codewars.com/kata/5824daf7c4d7f388600002a3

      It's an old JavaScript-only beta, though. Not sure if that would be enough of a reason to retire this one.

    • el-iot Avatar

      Thanks for the feedback guys! I've added some more random tests, including tests with longer keys (including some keys that are just symbols). I also added a description of how to handle empty-lists and empty dictionaries (they can exist in the nested structure, but only as values / endpoints because they aren't hashable (in python, at least). Does this help the kata, in your opinion? What more should I add if I am (stubbornly) hopeful that it will get published?

    • Blind4Basics Avatar

      I just looked at the test suite and...

      x/

      those are not random tests, they are fixed tests. => look at some others katas you solved (recent one if possible) and study how the random tests are done.

      Note: in your case, you'll have to compute the expected solution before you send the data to the user (or you'll need to make a deep copy of the structure)