keleshev / schema

Schema validation just got Pythonic
MIT License
2.88k stars 215 forks source link

Cross-validating Dictionary Values #264

Open pugantsov opened 3 years ago

pugantsov commented 3 years ago

Hi there, I was wondering if it were possible to check two dictionary values against each other.

The use case I have is that I have a list of dictionaries which I'm checking which consist of two key-value pairs. Both of these types of values are lists and I want to check that both lists are the same length. Is it possible for me to do so?

Stealthmate commented 2 years ago

This should be possible using something like

Schema(
  And(
    {
      'foo': [str],
      'bar': [str]
    },
    lambda d: len(d['foo']) == len(d['bar'])
  )
)