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
  • 104,438
  • 178
  • 489
  • 842

1 Answers1

0

You could use all:

all(a == array[0] for a in array[1:])
Thierry Lathuille
  • 23,663
  • 10
  • 44
  • 50