Message Boards Message Boards

How to verify that all the elements of a list are equal?

Posted 9 years ago

Hello all, I would like to ask your help in order to be able to solve solve my problem, I have several lists of this type, {1,1,1 } , {2,2,2 } , {0,0,0 } , {0,0 } , { 0 } , {2,1,4 },{3,5,6}, And I would like to see Mathematica do the following, if all the values in a list are the same, then they add the amount that was obtained by adding all the elements, for example the list {1,1,1 } has all its elements equal,then you must sum 3 since that is the result of adding 1 +1 +1, to obtain {1,1,1 } 3. The problem is that I do not know how to verify that all the elements of a list are equal, if anyone knows any way to do this please help me, thank you in advance

POSTED BY: Luis Ledesma
3 Replies
Posted 9 years ago

Many thanks @Hans Milton and @ David Reiss with your help I can solve my problem

POSTED BY: Luis Ledesma
Posted 9 years ago

Another alternative is:

Equal @@ list
POSTED BY: Hans Milton
Length[Union[list]]===1

Will test this... Or

MatchQ[list, {x_..}]
POSTED BY: David Reiss
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract