0
0
DSA Pythonprogramming~10 mins

Character Frequency Counting in DSA Python - Interactive Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to initialize an empty dictionary for counting characters.

DSA Python
freq = [1]
Drag options to blanks, or click blank then click option'
A''
B{}
Cset()
D[]
Attempts:
3 left
💡 Hint
Common Mistakes
Using a list [] instead of a dictionary.
Using a string '' which cannot store counts.
Using a set() which does not store counts.
2fill in blank
medium

Complete the code to loop through each character in the string 'text'.

DSA Python
for [1] in text:
    freq[char] = freq.get(char, 0) + 1
Drag options to blanks, or click blank then click option'
Achar
Bletter
Cword
Ditem
Attempts:
3 left
💡 Hint
Common Mistakes
Using a variable name different from the one inside the loop.
Using 'word' which implies multiple characters.
Using 'item' which is vague.
3fill in blank
hard

Fix the error in the code to correctly update the frequency count.

DSA Python
freq[char] = freq.[1](char, 0) + 1
Drag options to blanks, or click blank then click option'
Aget
Bset
Cadd
Dappend
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'add' which is not a dictionary method.
Using 'set' which replaces the whole dictionary.
Using 'append' which is a list method.
4fill in blank
hard

Fill both blanks to create a dictionary comprehension that counts characters only if they appear more than once.

DSA Python
freq = {char: text.count(char) for char in [1] if text.count(char) [2] 1}
Drag options to blanks, or click blank then click option'
Aset(text)
Blist(text)
Ctext
D>
Attempts:
3 left
💡 Hint
Common Mistakes
Using list(text) which includes duplicates.
Using '<' instead of '>' causing wrong filtering.
Using dict(text) which is invalid here.
5fill in blank
hard

Fill all three blanks to create a dictionary comprehension that counts characters and includes only those with count at least 2.

DSA Python
freq = [1]: [2] for [3] in set(text) if text.count(char) >= 2
Drag options to blanks, or click blank then click option'
A{char
Btext.count(char)
Cchar
Dchar:
Attempts:
3 left
💡 Hint
Common Mistakes
Missing the opening curly brace.
Using wrong variable names.
Incorrect order of key and value.