Question: Consider a list where every element is a nested list of length 2. The first element of each nested list is either a 0 or

Consider a list where every element is a nested list of length 2. The first element of each nested list is either a 0 or a 1. The second element of each nested list is some integer. As an example:

'((0 1) (1 2) (1 3) (0 4) (0 3))

For the purposes of this question, lets call the first element of each nested list thekey,and the second element of the nested lists thevalue. In racket, implement a function, count-by-cat, that takes such a list as input and yields a two element list where

  • the first element is the sum of the values of all nested lists with 0 as the key, and
  • the second element is the sum of the values of all nested lists with 1 as the key

It may be helpful to create helper functions. Also do not forget about map and filter.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!