0

I have an array of an unknown size with dictionaries in it. I'd like to check if all dictionaries are the same or not. Normally I would do either:

array[0] == array[1] == array[2] # with a known size

or:

len(set(array)) == 1 # if a hashable type

How would I do the above with an array of unknown size with dicts?

David542
  • 101,766
  • 154
  • 423
  • 727

1 Answers1

0

You could use all:

all(a == array[0] for a in array[1:])
Thierry Lathuille
  • 22,718
  • 10
  • 38
  • 45