🚀 Restarting My Problem-Solving Journey (with a twist) I’ve already solved several problems on LeetCode using Java ☕ But now, I’ve decided to solve them again using Python 🐍 Why? Because I want to strengthen my fundamentals and become flexible with different technologies. 🧩 Today’s Problem: Score of a String 💡 Approach: Traverse the string Compare adjacent characters Add the absolute difference of their ASCII values 💻 Solution (Python): def scoreOfString(s): score = 0 for i in range(len(s) - 1): score += abs(ord(s[i]) - ord(s[i + 1])) return score 🔍 What I noticed: Python makes the code shorter and more readable Logic remains the same, but implementation differs Re-solving problems improves problem-solving depth 📌 Goal: Build strong problem-solving skills + master Python for Data Analytics #LeetCode #Python #Java #ProblemSolving #CodingJourney #DataAnalytics #Consistency
Re-soloving LeetCode problems in Python to improve problem-solving skills
More Relevant Posts
-
Python has a dirty secret. It will let you write broken code that runs perfectly fine. No errors. No warnings. No stack traces. Just wrong answers, silently, confidently wrong. Scope bugs are the #1 reason this happens. You think you're reading a local variable. Python is reading a global one. Your function returns a result. The result is garbage. And the interpreter couldn't care less. I've seen this trip up beginners on day 3. I've seen it trip up senior engineers on year 5. The fix isn't talent. It's knowing the rules Python plays by. So I wrote them down. All of them. In plain English. Get the free Python Scope Guide: https://lnkd.in/djp6HJdD Save it. Share it. Send it to that colleague who keeps asking why their variable "has the wrong value". #Python #Programming #SoftwareEngineering #PythonTips
To view or add a comment, sign in
-
🚀 Python Secret #1: Even 257 Can Lie 😈 Most developers think: 👉 Every number creates a new object in Python. ❌ Not true. 🧠 Python preloads integers from -5 to 256 in memory. These values are reused instead of recreated. So this happens 👇 a = 256 b = 256 print(a is b) # True 😳 👉 Same memory object (guaranteed) --- But now the twist 👇 a = 257 b = 257 print(a is b) # True OR False 🤯 👉 Wait… what?! This is NOT caching. This is compiler optimization. ⚠️ Meaning: Sometimes Python reuses the object… Sometimes it doesn’t. --- 💀 Want the real truth? a = int("257") b = int("257") print(a is b) # False 🔥 👉 Now Python is forced to create different objects. --- 🧠 Key Difference: ✔️ "==" → checks value (SAFE) ❌ "is" → checks memory (UNRELIABLE for numbers) --- 🔥 Final Insight: “Optimization is not a guarantee. Only -5 to 256 is.” --- 💬 Did this surprise you? Follow for more Python secrets 🐍 Day 1/30 — Let’s master Python together 🚀 #Python #Coding #Programming #Developers #PythonTips #LearnToCode #Tech #AI #100DaysOfCode
To view or add a comment, sign in
-
-
Most teams do not reach for hashtag #PyFlink because Python feels nicer. They reach for it after paying the production cost of splitting one ML system across two ecosystems: Python for training, Java for prediction, and months lost to subtle feature mismatches, latency, and debugging. That is the real adoption driver. New on ML-Affairs: "If the real source of friction in your system is that your training, feature logic, and model-adjacent code live naturally in Python, then "just use Java hashtag #Flink" is not a neutral suggestion. It is an architectural trade, and often an expensive one." https://lnkd.in/e99uC3hU
To view or add a comment, sign in
-
Coming from Go, Python's type system felt loose to me at first. No compile step. No enforcement. Just... hints. But the more I dig in, the more I appreciate tools like `NewType` and `Literal`. In Go, the compiler stops you from mixing up types that share the same underlying type. Python can do something similar — not at runtime, but statically with Mypy. ```python from typing import NewType, Literal UserID = NewType("UserID", int) ProductID = NewType("ProductID", int) # Mypy catches this — both are ints, but they're not the same type process_order(ProductID(1), UserID(2)) # ❌ LogLevel = Literal["DEBUG", "INFO", "WARNING", "ERROR", "CRITICAL"] # Mypy catches this too set_log_level("WRONG") # ❌ ``` The discipline is on you to run the linter. But once you do, you get a surprisingly Go-like experience — catching swapped IDs and invalid strings before they ever hit production. Python's type system isn't weak. It's just opt-in. #Python #Go #TypeSafety #BackendEngineering #SoftwareDevelopment
To view or add a comment, sign in
-
-
Day 2 of my Python Full Stack journey. ✅ Today I covered the very first building block of Python: → Variables → Data Types (int, float, str, bool) → f-strings to print dynamic output Looks simple. But this is the foundation everything else is built on. Here's what I actually typed today: name = "Punith" # str age = 24. # int score = 9.5 # float is_dev = True # bool print("Hi, I'm {Punith}, age {24}") and many. One thing that clicked today: Python figures out the data type automatically. No need to declare it like in Java or C. This is called dynamic typing — and it makes Python so much cleaner to write. 45 minutes. Committed to GitHub. Showing up again tomorrow. If you're learning to code right now — what was the first concept that actually made sense to you? #PythonFullStack #Day2 #BuildingInPublic #100DaysOfCode #Bangalore
To view or add a comment, sign in
-
-
𝗣𝘆𝘁𝗵𝗼𝗻 𝗶𝘀 𝘀𝗹𝗼𝘄. Everyone knows it. But libraries like 𝗡𝘂𝗺𝗽𝘆, 𝗣𝗼𝗹𝗮𝗿𝘀 or 𝗣𝘆𝗱𝗮𝗻𝘁𝗶𝗰 are extremely fast... and they are written in Rust (or C/C++). What if you could do the same? I wrote an article explaining how to build a native 𝗥𝘂𝘀𝘁 library and use it from Python with 𝗣𝘆𝗢𝟯. The example is simple — the Sieve of Eratosthenes — but the numbers speak for themselves: 🦀 𝗥𝘂𝘀𝘁 → 271 µs 🐍 𝗣𝘆𝘁𝗵𝗼𝗻 → 9,297 µs ⚡ 𝟯𝟰𝘅 𝗳𝗮𝘀𝘁𝗲𝗿 And that includes the overhead of converting types between both languages. In the article I cover: → How Python's module system works → How to expose Rust functions to Python with PyO3 → Why the real speedup is even higher than what the benchmark measures → Tools like 𝗺𝗮𝘁𝘂𝗿𝗶𝗻 to simplify the workflow If you work with Python and have computational bottlenecks, Rust might be the missing piece. 🔗 https://lnkd.in/e8n4QC7j #Python #Rust #Performance #DataEngineering #SoftwareDevelopment
To view or add a comment, sign in
-
Python: @staticmethod vs @classmethod (Explained Simply) In Python classes, not all methods behave the same. There are 3 types of methods: 1) Instance Method: Works with object data. def show_name(self): • Uses self. • Accesses instance variables. 2) Class Method (@classmethod): Works with class-level data. @classmethod • Uses cls. • Can modify class variables. • Shared across all objects. 3) Static Method (@staticmethod): Independent utility function. @staticmethod • No self, no cls. • Doesn’t modify class or instance. • Used for helper logic. In this example: • show_name() → works on object. • change_company() → updates company for all employees. • greet() → simple helper function. Think of it like this: - Instance → works with object. - Class → works with class. - Static → works independently. Comment down, Which one do you use most in your code?
To view or add a comment, sign in
-
-
Day 7 of my Python Full Stack journey. ✅ Today's topic: Dictionaries — the most important data structure in Python. A dictionary stores data as key-value pairs. Think of it like a real dictionary — word (key) and its meaning (value). Here's what I typed today: student = { "name": "Punith", "age": 24, "course": "Python Full Stack" } # Access print(student["name"]) # Punith # Add / Update student["city"] = "Bangalore" # Loop through for key, value in student.items(): print(f"{key}: {value}") Why this matters for Django: Every Django model, every API response, every JSON data — all dictionary-like. If you understand dictionaries, Django will make sense. 60 minutes done. Pushed to GitHub. Day 8 tomorrow. One week and 2 days in. Still showing up. 💪 #PythonFullStack #Day7 #Dictionaries #BuildingInPublic #100DaysOfCode #Bangalore
To view or add a comment, sign in
-
-
Python scope is one of those topics that separates developers who debug fast from those who don't. The language gives you no warning when a variable resolves to an unexpected value. It simply executes, returns a result, and moves on. Tracking down the source of that behaviour - without a solid mental model of how Python resolves names - can cost hours. The LEGB rule isn't complicated. But it's rarely taught with the depth it deserves. I wrote a free guide to change that: → How Python's name resolution actually works under the hood → The LEGB lookup chain with concrete, practical examples → Enclosing scopes and closure behaviour explained clearly → When global and nonlocal are appropriate - and when they signal a design problem → The scope patterns most likely to introduce silent bugs in real codebases Download it free: https://lnkd.in/djp6HJdD #Python #SoftwareEngineering #PythonDevelopment #BackendDevelopment
To view or add a comment, sign in
-
Python's GIL is finally going away — and it's a bigger deal than most backend engineers realise. Free-threading (PEP 703) is now officially supported in Python 3.14. Early benchmarks are showing 10x+ speedups on parallelisable workloads. For years, the answer to "why not use threads for CPU-bound tasks in Python?" was always one word — GIL. That answer is changing. For those unfamiliar: the Global Interpreter Lock prevented multiple threads from executing Python bytecode simultaneously, effectively forcing developers to use multiprocessing for any real parallelism. It was Python's most famous limitation for over two decades. Now with free-threading reaching maturity, true multi-threaded Python is becoming a reality — without the overhead of spawning separate processes. Still early for production adoption, but the ecosystem is moving fast. Third-party packages are already updating their extension modules to support the new APIs. Python is no longer the "fast to write, slow to run" language it once was. Are you planning to test free-threading in your stack? Drop your thoughts below 👇 #Python #BackendEngineering #Python314 #FreeThreading #SoftwareDevelopment
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
Super vinod