QuestionQ27

VerifiedWorking with Data and Performing Simple Analyses

You are reviewing student survey responses about their favorite colors. The colors list holds the individual responses:

Question Image

You need to:

  • find the number of unique colors mentioned with NumPy, and
  • determine how frequently each color was selected using Counter.

Which code snippet correctly carries out both tasks? Select the best answer.

Explanation

numpy.unique returns the distinct elements in an array-like sequence, and taking its length yields the number of unique colors. collections.Counter counts occurrences of each element in the original sequence, producing the frequency for every color.

Learn more

Community Discussion

No comments yet. Be the first to start the discussion!