I have a dictionary, and I'm trying to check for the rare occurrence of all values having the same numerical value, say 1. How would I go about doing this in an efficient manner?
相关问题
- how to define constructor for Python's new Nam
- streaming md5sum of contents of a large remote tar
- How to get the background from multiple images by
- Evil ctypes hack in python
- Correctly parse PDF paragraphs with Python
You can also try this:
Inspired by some of the discussion from this other question:
Use
unanimous
to see if all dict values are the same:You cannot have key*s* with the same value. This means that there is only one key in your dictionary, because every subsequent one will overwrite the previous. If you are concerned that all keys have the values which are one. Then you do something like this:
I will assume you meant the same value:
If you want to check for a specific value, how about
this code will most often fail early (quickly)