0
0
DSA Pythonprogramming~30 mins

First Non Repeating Character Using Hash in DSA Python - Build from Scratch

Choose your learning style9 modes available
First Non Repeating Character Using Hash
📖 Scenario: Imagine you are building a simple text analyzer tool. One of the features is to find the first character in a sentence that does not repeat. This helps highlight unique characters for fun word games or puzzles.
🎯 Goal: Build a program that finds the first non-repeating character in a given string using a hash (dictionary) to count character occurrences.
📋 What You'll Learn
Create a string variable with a specific sentence
Create a dictionary to count characters
Use a loop to fill the dictionary with character counts
Use another loop to find the first character with count 1
Print the first non-repeating character or a message if none found
💡 Why This Matters
🌍 Real World
Finding unique characters is useful in text analysis, cryptography, and word games.
💼 Career
Understanding how to count and analyze data using dictionaries is a key skill in programming and data processing jobs.
Progress0 / 4 steps
1
Create the input string
Create a string variable called text and set it to the exact value 'swiss'.
DSA Python
Hint

Use single quotes around the word swiss.

2
Create a dictionary to count characters
Create an empty dictionary called char_count to store character counts.
DSA Python
Hint

Use curly braces {} to create an empty dictionary.

3
Count characters using a loop
Use a for loop with variable char to iterate over text. Inside the loop, update char_count[char] to count how many times each character appears.
DSA Python
Hint

Check if char is already a key in char_count. If yes, add 1; if no, set to 1.

4
Find and print the first non-repeating character
Use a for loop with variable char to iterate over text. Inside the loop, check if char_count[char] is 1. If yes, print char and break the loop. If no such character is found, print 'No non-repeating character found'.
DSA Python
Hint

Use a for-else structure to print the character or a message if none found.