Day 3 of my Python & DSA learning journey 🚀 A simple string completely confused me today 🤯 "A man, a plan, a canal: Panama" — is this a palindrome? At first glance I thought — no way, there are too many symbols! But Python solved it in just a few lines. Here's what I learned today 👇 ❓ Valid Palindrome (Ignore Symbols) A palindrome is a word that reads the same forward and backward. Examples: madam racecar But what if the string contains spaces, commas, or symbols? Example: "A man, a plan, a canal: Panama" It is still a palindrome — we just need to ignore the non-alphanumeric characters. 📌 Python provides a very useful function for this: isalnum() → it checks whether a character is a letter or a number. 💻 Example in Python s = "A man, a plan, a canal: Panama" result = "" for ch in s: if ch.isalnum(): result += ch.lower() if result == result[::-1]: print("Palindrome") else: print("Not Palindrome") Output: Palindrome ✅ Here we: • Removed symbols using isalnum() • Converted characters to lowercase using .lower() • Compared the string with its reverse Just a few lines of code — problem solved! 🔥 🔥 Question for developers: Is "race a car" a valid palindrome according to this logic? Drop your answer in the comments and explain why 👇 👀 Day 4 Teaser Tomorrow I’ll share a very interesting string trick used in coding interviews: How to check if two strings are rotations of each other in just one line of Python. Stay tuned 🚀 #Python #DSA #Coding #Programming #LearningInPublic #100DaysOfCode #PythonProgramming
Python Palindrome Checker with isalnum()
More Relevant Posts
-
🚀 Day 16 of Python Learning: Polymorphism in Python Today I learned about Polymorphism in Python — an important Object-Oriented Programming (OOP) concept where the same method name can behave differently for different objects. 🔹 What is Polymorphism? Polymorphism means "many forms." It allows one interface or method name to perform different actions based on the object. 🔸 Method Overriding Example class Animal: def sound(self): print("Animal makes sound") class Dog(Animal): def sound(self): print("Dog barks") class Cat(Animal): def sound(self): print("Cat meows") dog = Dog() cat = Cat() dog.sound() cat.sound() 🔸 Built-in Polymorphism Example print(len("Python")) print(len([1, 2, 3, 4])) 💡 Key Learning: The same method can behave differently depending on which object is calling it. 🧪 Practice Task: ✔ Create Shape class ✔ Create Circle and Rectangle classes ✔ Add area() method in both classes ✔ Call same method with different outputs 🎯 Interview Question: What is the difference between inheritance and polymorphism? Answer: Inheritance is used to reuse code from parent class, while polymorphism allows the same method name to perform different behaviors. 📌 Day 16 completed — understanding smarter OOP concepts! #Python #Learning #CodingJourney #Day16 #Programming #SDET #100DaysOfCode Masai #dailylearning #masaiverse
To view or add a comment, sign in
-
Day 11 of my Python learning journey Today I tried solving the Two Sum problem using the Two Pointer technique. Before this, I was only solving Two Sum using a dictionary. But today I learned another approach that works when the array is sorted. Problem: Two Sum (Two Pointer Approach) Given a sorted array and a target value, find two numbers whose sum equals the target. Example: nums = [1, 2, 4, 6, 10] target = 8 Output: [2, 6] Because 2 + 6 = 8. What is the Two Pointer technique? Two pointers means using two positions in the array: one pointer starts from the left side one pointer starts from the right side Then we move them based on the sum. How it works: • If the sum is too small, move the left pointer forward • If the sum is too large, move the right pointer backward • If the sum equals the target, we found the answer Code: nums = [1, 2, 4, 6, 10] target = 8 left = 0 right = len(nums) - 1 while left < right: s = nums[left] + nums[right] if s == target: print(nums[left], nums[right]) break elif s < target: left += 1 else: right -= 1 Problems I faced while coding this: At first I did not understand why the array needs to be sorted. I was confused about when to move the left pointer and when to move the right pointer. I also tried using this method on an unsorted array and it did not work. What I finally understood: The Two Pointer technique works well when the array is sorted because it lets us adjust the sum efficiently without checking every pair. This reduces the time complexity compared to nested loops. Question: Would this approach still work if the array was not sorted? #Python #DSA #Coding #Programming #LearningInPublic #100DaysOfCode #PythonProgramming
To view or add a comment, sign in
-
-
Day 18 of my Python learning journey Today I tried another good problem based on the Two Pointer technique. Problem: Merge Sorted Array Given two sorted arrays, merge them into one sorted array. Example: arr1 = [1, 3, 5] arr2 = [2, 4, 6] Output: [1, 2, 3, 4, 5, 6] What I understood: Since both arrays are already sorted, we do not need to sort again. We can compare elements from both arrays and place the smaller one first. Better approach (Two Pointer): One pointer for arr1 One pointer for arr2 Compare both values Add the smaller value to the result Code I wrote: arr1 = [1, 3, 5] arr2 = [2, 4, 6] i = 0 j = 0 result = [] while i < len(arr1) and j < len(arr2): if arr1[i] < arr2[j]: result.append(arr1[i]) i += 1 else: result.append(arr2[j]) j += 1 while i < len(arr1): result.append(arr1[i]) i += 1 while j < len(arr2): result.append(arr2[j]) j += 1 print(result) Problems I faced while coding this: At first I thought I had to combine both arrays and then sort them. I was confused about why two pointers are enough. I also forgot to handle the remaining elements after one array finishes. What I finally understood: Because both arrays are sorted, we can merge them in one pass. This saves extra sorting work and makes the solution efficient. Time and Space Complexity: Time Complexity: O(n + m) Space Complexity: O(n + m) Question: What will be the output for: arr1 = [1, 2, 7] arr2 = [3, 4] Today’s realization: Sometimes the best solution is not creating something new, but combining what is already ordered. #Python #DSA #Coding #Programming #LearningInPublic #100DaysOfCode #PythonProgramming
To view or add a comment, sign in
-
-
🚀 Day 27 of My Python Learning Journey 🚀 Today I explored one of the most powerful concepts in Python: Polymorphism. 📌 Topics I Learned: 🔹 Advantages of Polymorphism • Improves code reusability • Makes programs more flexible • Reduces complexity • Helps in writing cleaner and scalable code 🔹 Important Terminologies in Python Polymorphism • Method Overriding • Operator Overloading • Duck Typing • Magic Methods 🔹 Duck Typing Philosophy in Python “If it walks like a duck and talks like a duck, then it is a duck.” 🦆 Python does not care about the object type, it only cares whether the required method or behavior is present. 🔹 Operator Overloading Python allows us to redefine the behavior of operators for user-defined objects. Example: + operator can perform different tasks: • Addition for numbers • Concatenation for strings and lists 🔹 Method Overriding A child class can redefine the method of the parent class with its own implementation. 🔹 Magic Methods Used for Operator Overloading • add() → + • sub() → - • mul() → * • truediv() → / • lt() → < • gt() → > • eq() → == 🔹 Error Associated with + Operator Trying to add incompatible data types gives an error. Example: 5 + "Python" Output: TypeError: unsupported operand type(s) for +: 'int' and 'str' Learning polymorphism made me realize how Python gives flexibility to write smart and dynamic code. Excited to learn more every day! 💻✨ Thanks for your support G.R NARENDRA REDDY sir #Day27 #Python #Polymorphism #DuckTyping #OperatorOverloading #MethodOverriding #MagicMethods #PythonProgramming #CodingJourney #LearningPython #FutureDeveloper
To view or add a comment, sign in
-
-
Day 6 of my Python learning journey Today I tried solving a problem that looked easy at first, but understanding the logic took some time. Problem: Two Sum Given a list of numbers and a target value, find the indices of the two numbers that add up to the target. Example: nums = [4, 5, 1, 8] target = 9 Output: [0, 1] Because 4 + 5 = 9. Code I wrote: nums = [4, 5, 1, 8] target = 9 d = {} for i in range(len(nums)): num = nums[i] comp = target - num if comp in d: print("Indices:", d[comp], i) print("Values:", nums[d[comp]], nums[i]) break d[num] = i Problems I faced while coding this: At first I tried two nested loops, which worked but felt inefficient. I was confused about why we store numbers in a dictionary. The line d[num] = i also confused me because I didn’t understand why we save the index. It also took time to understand how comp = target - num helps find the pair. What I finally understood: Instead of checking every pair, we store numbers we have already seen in a dictionary. Then we check if the required number already exists. This reduces the time complexity from O(n²) to O(n). From tomorrow we will start something different. I’m planning to build a small Python project that will take about 1 week. Tomorrow I will share the project roadmap, and then we will start with Day 1 of the project. #Python #DSA #Coding #Programming #LearningInPublic #100DaysOfCode #PythonProgramming
To view or add a comment, sign in
-
-
Day 17 of my Python learning journey Today I tried another interesting problem using the Two Pointer technique. Problem: Valid Palindrome Given a string, check if it can become a palindrome after removing at most one character. Example: s = "abca" Output: True Because removing 'c' makes it "aba" which is a palindrome. What I understood: We need to check if the string is almost a palindrome, allowing one mistake. Better approach (Two Pointer): Start one pointer from left Start one pointer from right If characters match → move both pointers If mismatch → try skipping one character (either left or right) Code I wrote: def is_palindrome(s, left, right): while left < right: if s[left] != s[right]: return False left += 1 right -= 1 return True s = "abca" left = 0 right = len(s) - 1 while left < right: if s[left] != s[right]: if is_palindrome(s, left + 1, right) or is_palindrome(s, left, right - 1): print(True) else: print(False) break left += 1 right -= 1 else: print(True) Problems I faced while coding this: At first I tried removing every character and checking, which was inefficient. I was confused about which character to remove when mismatch happens. Writing a helper function for checking palindrome took some time to understand. What I finally understood: At the first mismatch, we only need to try two cases: skip left character skip right character If any one works, the string is valid. Time and Space Complexity: Time Complexity: O(n) Space Complexity: O(1) Question: What will be the output for: s = "abc" Today’s realization: Sometimes solving a problem is about allowing one controlled mistake. #Python #DSA #Coding #Programming #LearningInPublic #100DaysOfCode #PythonProgramming
To view or add a comment, sign in
-
-
🚀 Python Series – Day 12: List Comprehension (Write Short & Smart Code!) Till now, we used loops to create lists. But what if you can do it in one clean line? 🤔 👉 That’s where List Comprehension comes in! 🧠 What is List Comprehension? List comprehension is a short and powerful way to create lists. 👉 It replaces loops with a single line of code 🔧 Basic Syntax: [expression for item in iterable] ▶️ Example (Using Loop): numbers = [] for i in range(5): numbers.append(i) print(numbers) ⚡ Same Using List Comprehension: numbers = [i for i in range(5)] print(numbers) 👉 Output: [0, 1, 2, 3, 4] 🔥 With Condition: even = [i for i in range(10) if i % 2 == 0] print(even) 👉 Output: [0, 2, 4, 6, 8] 🎯 Why Use List Comprehension? ✔️ Short & clean code ✔️ Faster than loops ✔️ Easy to read (once you practice) 🔥 Pro Tip: Don’t overuse it 😄 👉 Use it when it makes code simple, not confusing ⚡ Quick Challenge: What will be the output? x = [i*i for i in range(4)] print(x) 👇 Comment your answer! 📌 Tomorrow: Lambda Functions (Anonymous Functions in Python) Follow me to learn Python step-by-step from basics to advanced 🚀 #Python #DataScience #Coding #Programming #LearnPython #Beginners #Tech #MustaqeemSiddiqui
To view or add a comment, sign in
-
-
🚀 Day 11 of Python Learning: Loops and Patterns in Python Today I practiced loops in Python and learned how to create patterns using nested loops. This helps improve logic building and problem-solving skills. 🔹 What are Patterns? Patterns are shapes or number/star designs created using loops. They are great for understanding loop control and nested loops. 🔸 Using For Loop for i in range(5): print("*") 🔸 Star Pattern Example for i in range(1, 6): print("*" * i) Output: * ** 🔸 Number Pattern Example for i in range(1, 6): for j in range(1, i + 1): print(j, end=" ") print() 💡 Key Learning: Nested loops are useful when one loop runs inside another loop, especially for patterns and matrix-style problems. 🧪 Practice Task: ✔ Print reverse star pattern ✔ Print square pattern using stars ✔ Print number triangle pattern ✔ Try same patterns using while loop 🎯 Interview Question: What is a nested loop in Python? Answer: A nested loop is a loop inside another loop. It is used when repeated iterations are needed within each cycle of the outer loop. 📌 Day 11 completed — logic building step by step! #Python #Learning #CodingJourney #Day11 #Programming #SDET #100DaysOfCode Masai #dailyleaning #masaiverse
To view or add a comment, sign in
-
Day 16 of my Python learning journey Today I tried another interesting problem using the Two Pointer technique. Problem: Squares of a Sorted Array Given a sorted array, return a new array of the squares of each number, also sorted. Example: arr = [-4, -1, 0, 3, 10] Output: [0, 1, 9, 16, 100] What I understood: Even though the array is sorted, squaring negative numbers can break the order. So we cannot directly square and sort. Better approach (Two Pointer): Left pointer at start Right pointer at end Compare squares of both ends Place the larger square at the end of result array Code I wrote: arr = [-4, -1, 0, 3, 10] n = len(arr) result = [0] * n left = 0 right = n - 1 pos = n - 1 while left <= right: if abs(arr[left]) > abs(arr[right]): result[pos] = arr[left] * arr[left] left += 1 else: result[pos] = arr[right] * arr[right] right -= 1 pos -= 1 print(result) Problems I faced while coding this: At first I tried squaring and sorting, but it increased time complexity. I was confused about why we compare absolute values. The idea of filling the result array from the end was not clear initially. Managing three pointers (left, right, pos) felt tricky. What I finally understood: The largest square will always come from either end of the array. So we place it at the end and move inward. Time and Space Complexity: Time Complexity: O(n) Space Complexity: O(n) Question: Why do we fill the result array from the end instead of the beginning? Today’s realization: Sometimes the trick is not in solving directly, but in thinking from the result side. #Python #DSA #Coding #Programming #LearningInPublic #100DaysOfCode #PythonProgramming
To view or add a comment, sign in
-
-
I started learning Python by copy-pasting code. Ran it. It worked. Felt like I was learning. I wasn't. So I changed how I approach it. First, I ask Claude to explain the code line by line. Then I close everything and rewrite it myself. No pasting. Then I break it on purpose. Change a value. Remove a line. Pass something wrong. Watch it crash. Read the error slowly. And here's the habit that actually stuck; I maintain an error book. Every error I hit, I write it down. What broke. Why. How I fixed it. Now when something fails, I follow this order: Try to solve it from memory first. If I can't, check the error book. If it's not there, go research it properly. Docs, articles, forums. AI is the last resort. Not the first. Because if I ask Claude every time something breaks, I'm not learning Python. I'm learning how to ask Claude. The error book made me remember more than any tutorial ever did. #Python #CloudSecurity #LearningInPublic
To view or add a comment, sign in
Explore related topics
Explore content categories
- Career
- Productivity
- Finance
- Soft Skills & Emotional Intelligence
- Project Management
- Education
- Technology
- Leadership
- Ecommerce
- User Experience
- Recruitment & HR
- Customer Experience
- Real Estate
- Marketing
- Sales
- Retail & Merchandising
- Science
- Supply Chain Management
- Future Of Work
- Consulting
- Writing
- Economics
- Artificial Intelligence
- Employee Experience
- Workplace Trends
- Fundraising
- Networking
- Corporate Social Responsibility
- Negotiation
- Communication
- Engineering
- Hospitality & Tourism
- Business Strategy
- Change Management
- Organizational Culture
- Design
- Innovation
- Event Planning
- Training & Development