Day 16 of Problem Solving Series In Python

Day 16 of Problem Solving Series In Python | Geethu Talks

Day 16 of Problem Solving Series

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:

  1. Names list ni set() loki marchali
  2. Set automatic ga duplicates teeseyyestundi
  3. len(set) unique count istundi
6 entries โ†’ 4 unique

๐Ÿ’ก 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


CodeMeaning
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

check out our website for more resources

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

Leave a Comment