Today I had problem with #Python which in hindsight looks obvious, but I got too much tunnel vision. See: >>> s = (s1 if isinstance(s1, str) else s2 if isinstance(s2, str) else '') >>> s '' So we got fall-through here. But >>> print(type(s1), type(s2)) <class 'str'> <class 'str'> Well, there was no fall-through, it was a tunnel vision: s1 was empty string, so s got s1 value.
Alexey Vyskubov’s Post
More Relevant Posts
-
Friday brings #Python Today, let’s explore something interesting. If you read io.BytesIO via io.TextIOWrapper inside a function scope, you might lose your data. When the TextIOWrapper is garbage-collected, it automatically closes the underlying BytesIO stream, wiping your bytes! Be careful! Don’t let AI take your job.
To view or add a comment, sign in
-
-
Day 54 of 365 Days of code 1) Capacity to Ship Packages Within D Days Approach: Binary search 1)set low = max(weights) 2) high= low*sum(weights) 3) perform the below steps until low<=high condition fails i) mid=low+(high-low)//2;res=0 ii) set w = mid and initialize day=1 iii) iterate through the loop and perform the stuff i put in screenshot (ahh life hurts :") ) iv) if the day <= days: set res=mid ; set high=mid-1 v) else low=mid+1 4) return res #365daysOfCode #NeetCode #leetcode #DSA #python #LeetCode #ProblemSolving #Algorithms #365dayschallenge
To view or add a comment, sign in
-
-
Python cleaning tip that saved my time: Don’t loop over rows for simple replacements → use vectorized ops. Slow: --------------- for i in df.index: if df.at[i, 'status'] == 'act': df.at[i, 'status'] = 'active' Fast: ---------------- df['status'] = df['status'].replace('act', 'active') Vectorized = 10–100× faster. #Python #DataEngineering #Pandas #PerformanceTips #MomInTech #WomenInTech #LearningEveryday
To view or add a comment, sign in
-
THE PAIN: Too many developers get bogged down in complex, repetitive code. It's easy to write functions that do similar things over and over, making our code harder to read and debug. THE INSIGHT: This often happens because we're thinking about how to break a big problem into smaller, identical sub-problems. It's a natural way the human brain works. THE FIX: Let's use recursion. Consider calculating factorial. Instead of looping, we can define factorial(n) as n * factorial(n-1). The base case is factorial(0) = 1. Here's Python: def factorial(n): if n == 0: return 1 else: return n * factorial(n-1) THE OUTCOME: This approach simplifies logic for many problems. It leads to cleaner, more elegant code. Fewer bugs. Better focus. #Recursion #Python #SoftwareEngineering #CleanCode
To view or add a comment, sign in
-
-
How many NaNs in a #Python #Pandas series? Use isna (returns True/False) then sum/value_counts: s = pd.Series([10, 20, np.nan, 40, 50, np.nan, 70, 80]) s.isna().sum() # returns 2 s.isna().value_counts() # count True/False Hint: Pass normalize=True for the percentage
To view or add a comment, sign in
-
-
Built an MCP server from scratch to understand how the protocol actually works step by step. It is a practical tutorial to understand how MCP works under the hood instead of treating it like magic. Repo -> https://lnkd.in/gqGe7W6R #Python #AI #MCP #SoftwareEngineering #Backend
To view or add a comment, sign in
-
-
🚀 Day 4 – DSA Daily Series Move Zeroes (LeetCode 283) using Python. 🧠 Problem Given an integer array nums, move all 0’s to the end of the array while maintaining the relative order of the non-zero elements. Important constraints: • The operation must be done in-place • No extra array should be created Example: Input: nums = [0,1,0,3,12] Output: [1,3,12,0,0] 💡 Approach Used the Two Pointer technique. • Maintain a pointer k to track the position for the next non-zero element • Traverse the array using index i • Whenever a non-zero element is found, swap it with the element at position k • Increment k This ensures: • Non-zero elements move to the front • Zeros automatically shift toward the end ⏱ Complexity Time Complexity: O(n) – single pass through the array Space Complexity: O(1) – in-place modification 🔎 Key Learning This problem helps strengthen: • Two Pointer pattern • In-place array manipulation • Maintaining relative order while rearranging elements Consistency is key when practicing DSA — solving one problem at a time. 🚀 #DSA #LeetCode #Python #Algorithms #ProblemSolving #CodingJourney
To view or add a comment, sign in
-
-
Pipelines aren't lists. They're graphs. 🕸️ Most frameworks make you order everything manually. You get it wrong. It crashes. You reorder. Repeat. FRAMEWORM resolves execution order automatically. Detects circular dependencies before runtime. Runs independent nodes in parallel. Caches results so unchanged nodes never re-run. 2-4x faster. Zero babysitting. That's the Dependency Graph Engine. 📦 pip install frameworm #MLOps #MachineLearning #Python #GenerativeAI
To view or add a comment, sign in
-
More from this author
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
Why not just write a function and unit test etc