0

I am trying to validate a dict which contains stringified integers as keys. These ints are arbitrary numerical IDs, and out of my control.

How could I declare this in a schema?

Maybe there's a way to declare a default schema which I could use as a catch-all?

Thanks.

http://marshmallow.readthedocs.org/en/latest/index.html

mseery
  • 1,404
  • 2
  • 16
  • 26
  • You can get all of the keys of the dict with dict.keys() and then iterate over all of them with something like `for k in d.keys(): validate k and d[k]` – wpercy Jan 08 '16 at 20:05

1 Answers1

0

The way I prefer, use a map instead of if statement:

for key, value in dictionary.items():
    dictionary[
        {
         "True": str(key), 
          "False": <build a random key> 
        }.get(str(isinstance(key, int)))
     ] = value

Note: works only on Python3+

tuned
  • 1,085
  • 10
  • 14