Find First Non-Repeating Character
Find first character that appears only once.
AdvancedPhase 5 - Category 5: Advanced String LogicExample 8 of 14
find-first-non-repeating-character.py
1# Take string input2s = input("Enter a string: ")34# Find first non-repeating5freq = {}6for char in s:7 freq[char] = freq.get(char, 0) + 189# Find first with count 110result = None11for char in s:12 if freq[char] == 1:13 result = char14 break1516if result:17 print(f"First non-repeating: {result}")18else:19 print("No non-repeating character")
Output
Enter a string: hello First non-repeating: h
What's going on
Count frequency, then find first with count 1.
Key Concepts:
Count frequency of each character
Find first character with count 1
Return that character
🔗Related Content
- 📖
Phase 5 - Learn Concepts
Review Phase 5 concepts and explanations
- 📝
Phase 5 - Quiz
Test your Phase 5 understanding with quiz questions
- 💻
Phase 5 - All Practice Problems
Explore all practice problems for Phase 5
- 🎓
Master Your Logic Building - Complete Course
Browse all phases and tutorials
- 🧠
Logic Building Overview
Learn about the complete logic building curriculum