Advertisement
Guest User

Untitled

a guest
Sep 23rd, 2019
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.76 KB | None | 0 0
  1. try:
  2. from collections.abc import Mapping
  3. from collections.abc import Sequence
  4. except ImportError:
  5. from collections import Mapping
  6. from collections import Sequence
  7. import six
  8.  
  9. def foo(desire, current):
  10. if isinstance(desire, Mapping):
  11. return isinstance(current, Mapping) and all(
  12. foo(val, current.get(key))
  13. for key, val in six.viewitems(desire)
  14. )
  15. elif isinstance(desire, Sequence) and not isinstance(
  16. desire, six.string_types
  17. ):
  18. return (
  19. isinstance(current, Sequence)
  20. and not isinstance(current, six.string_types)
  21. and len(current) == len(desire)
  22. and all(foo(d, c) for d, c in zip(desire, current))
  23. )
  24. else:
  25. return desire == current
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement