Skip to main content
2 of 2
edited tags
Alexey Popkov
  • 62.3k
  • 7
  • 154
  • 375

Which condition?

I want to substitute integers in a list with theirs square, I tried these

Cases[{{1, 2, 3}, a, {4, 5}}, t__ /; Element[t, Integers] :> t^2]
(*{{1, 4, 9}, {16, 25}}*)
Cases[{{1, 2, 3}, a, {4, 5}}, t__ /; IntegerQ[t] :> t^2]
(*{}*)

Why the first code works and the second doesn't? What is the difference between Element and IntegerQ?

Giancarlo
  • 712
  • 4
  • 11