Pradumya Gupta’s Post

🚀 Day 55 of #100DaysOfCode — Counting Characters & Pythonic Efficiency Hey everyone! 👋 Today was all about String Manipulation. The task was to write a function that returns the total number of characters in a given string. While it’s a simple concept, it’s a great exercise to visualize how data is traversed in memory. 👨💻 What I practiced today: ✅ String Iteration: Using a for loop to step through a string character by character. ✅ Counter Logic: Manually incrementing a variable to track the sequence length. ✅ Edge Case Handling: Ensuring the function correctly returns 0 for an empty string "". 📌 Today’s Task: ✔ Given a string s. ✔ Traverse the string and count every character. ✔ Return the final count. 🧠 Key Insight: In my solution today, I manually built a counter (O(n) time). However, in Python, the len() function is the most efficient way to do this. Unlike a manual loop, len() is O(1) (constant time) because Python stores the length of the string as an attribute in memory! ✨ Key Takeaway: Learning the manual logic behind basic tasks is essential for mastering algorithms, but knowing when to use built-in functions like len() is what makes your code professional and performant. #100DaysOfCode #Day55 #Python #CodingJourney #DSA #Strings #CleanCode #LogicBuilding #SoftwareEngineering #Programming

  • No alternative text description for this image

To view or add a comment, sign in

Explore content categories