0

我正在尝试验证一个包含字符串化整数作为键的字典。这些整数是任意数字 ID,不受我的控制。

我如何在模式中声明它?

也许有一种方法可以声明一个我可以用作包罗万象的默认模式?

谢谢。

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

4

1 回答 1

0

我喜欢的方式是使用地图而不是if statement

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

注意:仅适用于 Python3+

于 2016-01-08T21:29:53.713 回答