Bird
0
0

You have training data with repeated labels:

hard📝 Application Q8 of 15
AI for Everyone - How AI Models Actually Work
You have training data with repeated labels:
data = ['apple', 'banana', 'apple', 'banana', 'banana']

How can you create a dictionary showing the frequency of each label using dictionary comprehension?
A{label: data.count(label) for label in set(data)}
B{label: data.index(label) for label in data}
C{label: 1 for label in data}
D{label: len(data) for label in set(data)}
Step-by-Step Solution
Solution:
  1. Step 1: Understand dictionary comprehension for counting

    Use set(data) to get unique labels, then count each label's occurrences.
  2. Step 2: Check each option

    {label: data.count(label) for label in set(data)} correctly counts frequency; others do not count properly.
  3. Final Answer:

    {label: data.count(label) for label in set(data)} -> Option A
  4. Quick Check:

    Use set and count for frequency dict [OK]
Quick Trick: Use set and count inside dict comprehension [OK]
Common Mistakes:
  • Using index instead of count
  • Assigning 1 to all labels
  • Using length of data for all keys

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More AI for Everyone Quizzes