0
0
DSA Pythonprogramming~10 mins

First Non Repeating Character Using Hash 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 create a dictionary to count characters.

DSA Python
count = [1]()
Drag options to blanks, or click blank then click option'
Adict
Blist
Cset
Dtuple
Attempts:
3 left
💡 Hint
Common Mistakes
Using list or set instead of dictionary for counting.
Trying to use tuple which is immutable.
2fill in blank
medium

Complete the code to increment the count of character c in the dictionary.

DSA Python
count[c] = count.get(c, 0) [1] 1
Drag options to blanks, or click blank then click option'
A+
B-
C*
D/
Attempts:
3 left
💡 Hint
Common Mistakes
Using minus or multiplication instead of addition.
Forgetting to handle the default count with get.
3fill in blank
hard

Fix the error in the loop to find the first non-repeating character.

DSA Python
for c in s:
    if count[c] == [1]:
        return c
Drag options to blanks, or click blank then click option'
A0
B-1
C2
D1
Attempts:
3 left
💡 Hint
Common Mistakes
Checking for count 0 or 2 instead of 1.
Using negative numbers which don't make sense here.
4fill in blank
hard

Fill both blanks to complete the function that returns the first non-repeating character or '_' if none.

DSA Python
def first_non_repeating(s):
    count = dict()
    for c in s:
        count[c] = count.get(c, 0) [1] 1
    for c in s:
        if count[c] == [2]:
            return c
    return '_'
Drag options to blanks, or click blank then click option'
A+
B-
C1
D0
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong operators for increment.
Checking for count 0 instead of 1.
5fill in blank
hard

Fill all three blanks to create a dictionary comprehension that counts characters appearing more than once.

DSA Python
count = [1]( (c, s.count(c)) for c in s if s.count(c) [2] [3] )
Drag options to blanks, or click blank then click option'
Adict
B>
C1
D<
Attempts:
3 left
💡 Hint
Common Mistakes
Using list or set instead of dict.
Using less than instead of greater than.
Checking for count equal to 1 instead of greater than 1.