0

What are the glom tricks to be able to say "collect all of them".

An example of what I mean: What would the glom way of extracting

{'a': [[11], [22, 22]], 'b': [[33, 33, 33], [44, 44, 44, 44]]}

from

target = {
    'a': {
        1: {
            'one': [1],
            'another': [11]
        },
        2: {
            'one': [2, 2],
            'another': [22, 22]
        }
    },
    'b': {
        1: {
            'three': [3, 3, 3],
            'another': [33, 33, 33]
        },
        2: {
            'four': [4, 4, 4, 4],
            'another': [44, 44, 44, 44]
        }
    }
}

be?

Not a hardcoded spec like {'a': ..., 'b': ...}, but one that will "go through all" keys (here at the first level). Note there's also a "go through all" at the second level, but the instruction here is to ignore the key and just accumulate what ever the lower levels yield.

This might be another instance where boltons remap is needed in cooperation with glom.

thorwhalen
  • 1,920
  • 14
  • 26
  • what's wrong with using pure python for this – gold_cy Sep 01 '20 at 18:59
  • @gold_cy: The same thing that's wrong with pure python, or assembly for that matter, in any other case. There's nothing wrong with using a bunch of bicycles tied together to transport 2 tons of bricks. But if you have a truck, better use that. For the task of extracting information from nested structures, you can use a bunch of `for` and `if` statements, or you can use your truck: `glom`. – thorwhalen Sep 01 '20 at 20:47
  • we can agree to disagree, the problem statement is alot simpler than you think and does not require some third party libraries in order to solve. – gold_cy Sep 01 '20 at 21:10
  • @gold_cy. Sorry to disagree again, but the problem is obviously a lot harder than you think, since you think it's simple. I'm really not sure what the right etiquette is on this platform. Perhaps you can help on that. I tend to spend the time to carefully craft an easy example to illustrate a problem, but most, like you, just respond with something along the lines of "you're approaching it wrong", or "you don't need that", rather than just answer the question, giving the questioner the benefit of the doubt. – thorwhalen Sep 02 '20 at 14:12
  • I'd suggest you have a 10mn peep at [glom](https://glom.readthedocs.io/en/latest/). If you deal with nested structures, those 10mn will give you a quick profit over pure python. And if you're world is flat, you'll at least learn by exposure to good code. – thorwhalen Sep 02 '20 at 14:17

0 Answers0