I'm using Python and I'm trying to figure out how to ascertain whether all numbers in a list are the same or different (even with just one integer being different) if beforehand I don't know the total number of elements in the list. Initially I wrote something like:
def equalOrNot(lst):
if sum(lst)%len(lst)==0:
return False
else:
return True
But it's not working in all cases. Any suggestions? Thanks
Use set
:
if len(set(lst)) == 1:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With