What is Nostr?
Scott Miller πŸ‡ΊπŸ‡¦ πŸ‡ΊπŸ‡Έ /
npub1n3d…3lte
2024-03-27 14:12:36

Scott Miller πŸ‡ΊπŸ‡¦ πŸ‡ΊπŸ‡Έ on Nostr: Python Question: Is there an efficient way to see if every element in an iterable is ...

Python Question: Is there an efficient way to see if every element in an iterable is equal to a user-specified value?

The best idea I've seen so far is to use a list comprehension to check for equality, and then use the all function, like this:
MyList = [1,1,1,1,1,1,1]
all((x==1 for x in MyList))

That's readable and probably not bad performance. Is there something better?

#Python #PythonQuestion
Author Public Key
npub1n3de0wff4nmcdy7pe0cqwqkaup2lslu4y5hf8zqfqa3tqrtxz4kq9e3lte