Day 16 of Problem Solving Series In Python | Geethu Talks

Table of Contents
Day 16 of Problem Solving Series
๐ Hi friends! Geethu Talks ki welcome. Oke person rendu sarlu register chesaru ante? Ee roju sets tho duplicates ni oka line lo teeseddam.
๐ฌ Reel chudaledha? Instagram / YouTube lo @GeethuTalks ni follow avvandi.
๐งฉ Real-life Problem
College event registration list lo konni names repeat ayyayi. Asalu entha mandi unique participants unnaru?
๐ Task: Names list nunchi duplicates teesesi, unique participants count cheyyandi.
๐ฅ Sample input: Ravi, Sita, Ravi, Arjun, Sita, Geethu
๐ค Sample output: Unique participants: 4
๐ Concepts Covered
- ๐งบ
setโ unique values matrame - โ๏ธ Duplicate removal
- ๐
len()on a set - ๐ค
sorted()tho order lo chupinchadam
๐ง Step 1: Logic Build Cheddam
List lo duplicates untayi. Set lo duplicates undavu:
- Names list ni
set()loki marchali - Set automatic ga duplicates teeseyyestundi
len(set)unique count istundi
๐ก Analogy: Set ante oka bag: oke peru rendu sarlu vesthe, bag lo okkate untundi.
๐ป Step 2: Python Code
names = ["Ravi", "Sita", "Ravi", "Arjun", "Sita", "Geethu"]
unique = set(names)
print(f"Total entries: {len(names)}")
print(f"Unique participants: {len(unique)}")
print(sorted(unique))
โ
Output
Total entries: 6
Unique participants: 4
[‘Arjun’, ‘Geethu’, ‘Ravi’, ‘Sita’]
๐ Line by line
| Code | Meaning |
|---|---|
set(names) | List nunchi duplicates teesesi set create |
len(names) | Duplicates tho kalipi motham entries |
len(unique) | Unique participants |
sorted(unique) | Sets ki order undadu, anduke sort chesi chupinchadam |
โ ๏ธ Common Mistake Alert
โ Wrong: Unique count kosam len(names) vadadam. Duplicates kuda count avuthayi
names = ["Ravi", "Sita", "Ravi", "Arjun", "Sita", "Geethu"]
print(len(names)) # 6, not 4
Result:
6
โ
Right: Mundu set(names) chesi, tarvatha len() teesukondi.
๐ก Bonus tip: {} empty set kaadu, adi empty dictionary! Empty set kosam set() rayandi.
๐ Quick Recap
- โ๏ธ Set lo duplicates undavu
- โ๏ธ
set(list)tho duplicates teesestham - โ๏ธ Sets ki order undadu
๐๏ธ Practice Problems
๐ข Easy: [1, 2, 2, 3, 3, 3] lo unique numbers entha?
Expected output: 3
๐ก Medium: Rendu friend lists lo common names kanukkondi (hint: &): A = Ravi, Sita, Arjun; B = Sita, Geethu, Arjun.
Expected output: [‘Arjun’, ‘Sita’]
๐ด Challenge: [4, 2, 7, 2, 9, 4] lo first repeated number entha? (hint: ‘seen’ set)
Expected output: 2
๐ฌ Mee answers comments lo share cheyyandi!
๐ Next: Day 17 โ Electricity Bill Calculator
Follow @GeethuTalks and stay tuned! ๐
โฌ ๏ธ Previous: Day 15 of Problem Solving Series In Python


1 thought on “Day 16 of Problem Solving Series In Python”