# Take elements from a list based on two criteria

I am trying to take elements from a list of tuples using 2 criteria. An example of the list is:

list={{-1, -1}, {-1, 1}, {1, 1}, {1, -1}, {1, (1 + I)/Sqrt}}


And I need to take the elements that contain one value $$=1$$ and a second value $$\neq1$$. Thus at the end, I will have

    list2={{-1, 1}, {1, -1}, {1, (1 + I)/Sqrt}}


Ive been trying using select as

list2 = Flatten[Table[Select[list[[i]], # == 1 &, 2]], {i, 1,5}], 1];


but the problem is that the values $$=1$$ do not have a "fixed column". Is there a way to do this avoiding an "if" statement?. Thanks in advance.

Select[list, Count[#, 1] == 1&]


{{-1, 1}, {1, -1}, {1, (1 + I)/Sqrt}}

Also

Pick[list, Lookup[Counts /@ list, 1, 0], 1]


{{-1, 1}, {1, -1}, {1, (1 + I)/Sqrt}}

And alternative ways to use Cases:

Cases[{OrderlessPatternSequence[1, Except]}]@list
Cases[_?(Counts[#] == 1&)]@list


{{-1, 1}, {1, -1}, {1, (1 + I)/Sqrt}}

• Oh, Thanks!. Do you know if the "Select" case can be used as a list?, eg, list[[i]]. This, because I have to track with the case, was not eliminated, For example, at the end, I will have element2-{-1,1}
– mors
May 22, 2019 at 15:08
• @mors, the output from all methods is a list.So, using selected = Select[list, Count[#, 1] == 1&], you can access its parts as, say, selected[] (which is {1, -1}) and selected[] - {-1,1} gives {2, -2}.
– kglr
May 22, 2019 at 15:20
• Thank you, I said it because every element in list is the output of a matrix, so my final goal is to construct llist2with the elements that were not erased from list and the name of the matrix that they correspond. e.g list2={{mat2-{1-1}, mat3-{-1,1}]. So I was wondering if I can use something as list2 = Flatten[ Table[ToString[ tabmatrices[[i]] <> "-" <> ToString[ Select[list[[i]], Count[#, 1] == 1&] ]], {i, 1,5}], 1];
– mors
May 22, 2019 at 16:07

You could use Cases instead:

Cases[list, {1,Except}|{Except,1}]


{{-1, 1}, {1, -1}, {1, (1 + I)/Sqrt}}

Paranoid version of kglr's Count solution:

Select[list, Total[Boole[PossibleZeroQ[# - 1]] & /@ #] == 1 &]


{{-1, 1}, {1, -1}, {1, (1 + I)/Sqrt}}

You can also use the following construction:

 lst = {{-1, -1}, {-1, 1}, {1, 1}, {1, -1}, {1, (1 + I)/Sqrt}}
Cases[lst, {x_, y_} /; (x == 1 && y != 1) || (y == 1 && x != 1)]
`

Which may be more helpful in certain situations.