Skip to main content
added 3 characters in body
Source Link
Sjoerd Smit
  • 24.8k
  • 48
  • 80

If you only need the counts, then CountsBy is the way to go:

CountsBy[Range[100], EvenQ]

You can also do it with the 3rd argument of GroupBy:

GroupBy[Range[100], EvenQ, Length]

If you want the results in a list in a particular order (say, even then odd), you can use Lookup:

Lookup[CountsBy[Range[100], EvenQ], {True, False}, 0]

If you only need the counts, then CountsBy is the way to go:

CountsBy[Range[100], EvenQ]

You can also do it with the 3rd argument of GroupBy:

GroupBy[Range[100], EvenQ, Length]

If you want the results in a list a particular order (say, even then odd), you can use Lookup:

Lookup[CountsBy[Range[100], EvenQ], {True, False}, 0]

If you only need the counts, then CountsBy is the way to go:

CountsBy[Range[100], EvenQ]

You can also do it with the 3rd argument of GroupBy:

GroupBy[Range[100], EvenQ, Length]

If you want the results in a list in a particular order (say, even then odd), you can use Lookup:

Lookup[CountsBy[Range[100], EvenQ], {True, False}, 0]
Source Link
Sjoerd Smit
  • 24.8k
  • 48
  • 80

If you only need the counts, then CountsBy is the way to go:

CountsBy[Range[100], EvenQ]

You can also do it with the 3rd argument of GroupBy:

GroupBy[Range[100], EvenQ, Length]

If you want the results in a list a particular order (say, even then odd), you can use Lookup:

Lookup[CountsBy[Range[100], EvenQ], {True, False}, 0]