Topic 4/100 🚀 🧠 Topic 4 — Generators Processing large data and running out of memory? 😵 This concept solves that problem. 👉 What is it? Generators are functions that return values one at a time using yield instead of returning everything at once. 👉 Use Case: Used in real-world applications for: Reading large files Data streaming Handling APIs with pagination 👉 Why it’s Helpful: Saves memory Improves performance Enables lazy evaluation (data generated only when needed) 💻 Example: def count_up_to(n): for i in range(n): yield i for num in count_up_to(5): print(num) 🧠 What’s happening here? Instead of storing all values in memory, the function generates them one by one when needed. ⚡ Pro Tip: If you're working with large datasets, always think “generator” before using lists. 💬 Follow this series for more Topics #Python #BackendDevelopment #100TopicOfCode #SoftwareEngineering #LearnInPublic
Generators Solve Memory Issues in Python
More Relevant Posts
-
Topic 5/100 🚀 🧠 Topic 5 — Iterators Ever wondered how a for loop actually works behind the scenes? 🤔 This is the concept powering it. 👉 What is it? Iterators are objects that allow you to traverse through data step-by-step using __iter__() and __next__() methods. 👉 Use Case: Used in real-world applications for: Custom data pipelines Streaming data Building your own iterable objects 👉 Why it’s Helpful: Gives full control over iteration Enables custom looping logic Foundation for generators 💻 Example: class Counter: def __init__(self, max): self.max = max self.current = 0 def __iter__(self): return self def __next__(self): if self.current < self.max: self.current += 1 return self.current raise StopIteration for num in Counter(3): print(num) 🧠 What’s happening here? We created a custom object that behaves like a loop by controlling how values are returned one by one. ⚡ Pro Tip: If you understand iterators, you’ll unlock how Python handles loops internally. 💬 Follow this series for more Topics #Python #BackendDevelopment #100TopicOfCode #SoftwareEngineering #LearnInPublic
To view or add a comment, sign in
-
-
Don't flatten what naturally has structure. It's tempting to model everything in a single class. Easy to write, easy to read, at least until your data grows. This is where most codebases start, with just one model. But with model composition, each model has a single responsibility. And Pydantic handles nested validation automatically. Structure your models the way your domain is actually structured. The code gets cleaner, the errors get clearer, and reuse becomes obvious. This and other real-world modelling patterns are covered in Practical Pydantic: 👉 https://lnkd.in/eGiB7ZxU Model your domain. Not just your data. #Python #Pydantic #Data #Models #Patterns
To view or add a comment, sign in
-
-
Vector databases are great, but they aren't always the right tool for complex document intelligence. 🧠📉 If you are tired of context fragmentation and untraceable LLM hallucinations, it is time to look at Vectorless RAG with Page Index. By swapping out mathematical embeddings for a reasoning-based, hierarchical document tree, you can achieve upwards of 98% accuracy on complex Q&A tasks with perfect citation traceability. I wrote a complete guide on how this architecture works, including a full Python code implementation. Read it here: https://lnkd.in/gRuXiSxK #ArtificialIntelligence #RAG #PythonDeveloper #MachineLearning #AIEngineering
To view or add a comment, sign in
-
-
I recently worked on a project focused on optimizing pathfinding algorithms — and it gave me a deeper appreciation for how efficient systems are built. 🚀 Project: Pathfinding Algorithm Optimization 🔧 What I did: • Built a route optimization tool using Dijkstra’s and A* algorithms • Modeled real-world road networks using geospatial data • Used Python with OSMnx and NetworkX to simulate city navigation 📊 Results: Improved traversal efficiency by ~65% by applying heuristic-based optimizations. 📍 What I learned: • How algorithms behave in real-world scenarios (not just theory) • The impact of heuristics on performance • How to visualize complex data to make it understandable One thing that stood out — small optimizations can lead to significant performance gains when working with large-scale systems. Still exploring and improving my understanding of algorithms and backend systems. Would love to hear your thoughts or feedback! #SoftwareEngineering #Python #Algorithms #DataStructures #LearningInPublic #TechProjects
To view or add a comment, sign in
-
✅ Day 83 of 100 Days LeetCode Challenge Problem: 🔹 #832 – Flipping an Image 🔗 https://lnkd.in/ghfEcHHT Learning Journey: 🔹 Today’s problem involved two operations on a binary matrix: horizontal flip and bit inversion. 🔹 First, I reversed each row to achieve the horizontal flip. 🔹 Then, I inverted every bit (0 → 1 and 1 → 0) using a helper function. 🔹 This approach ensured the transformation was done in-place without extra space. Concepts Used: 🔹 Array Manipulation 🔹 Matrix Traversal 🔹 Two-Pointer / In-place Operations 🔹 Bit Manipulation Key Insight: 🔹 Instead of treating flipping and inversion as separate heavy operations, they can be efficiently combined or done sequentially in-place. 🔹 Using simple transformations keeps the solution clean and optimal. Complexity: 🔹 Time: O(n × m) 🔹 Space: O(1) #LeetCode #Algorithms #DataStructures #CodingInterview #100DaysOfCode #SoftwareEngineering #Python #ProblemSolving #LearningInPublic #TechCareers
To view or add a comment, sign in
-
-
✅ Day 98 of 100 Days LeetCode Challenge Problem: 🔹 #338 – Counting Bits 🔗 https://lnkd.in/gXdNxX66 Learning Journey: 🔹 Today’s problem focused on counting the number of 1s in the binary representation of numbers from 0 to n. 🔹 I initialized an array ans of size n+1. 🔹 For each number i, I converted it to binary using bin(i)[2:]. 🔹 Counted the number of '1' bits by iterating through the binary string. 🔹 Stored the count in ans[i] and returned the final array. Concepts Used: 🔹 Bit Manipulation (Binary Representation) 🔹 Array Traversal 🔹 String Processing 🔹 Brute Force Approach Key Insight: 🔹 Each number’s bit count can be computed independently. 🔹 Converting to binary and counting '1' works, but can be optimized further using DP or bit tricks. Complexity: 🔹 Time: O(n log n) (binary conversion for each number) 🔹 Space: O(n) #LeetCode #Algorithms #DataStructures #100DaysOfCode #Python #CodingJourney #ProblemSolving #LearningInPublic
To view or add a comment, sign in
-
-
Day 22/100 – DSA Journey Problem: Find Mode in Binary Search Tree (BST) Today’s problem focused on understanding how Binary Search Trees (BST) behave and how we can efficiently extract useful insights from them. Understanding the BST A Binary Search Tree follows a structured property: Left subtree → values ≤ root Right subtree → values ≥ root Because of this, when we perform an Inorder Traversal (Left → Root → Right), the values are visited in sorted order. Why Inorder Traversal? Since duplicates appear consecutively in a sorted sequence, inorder traversal allows us to: Track frequency without using extra space Compare current value with previous value Efficiently determine the most frequent element (mode) Approach Used Traverse the BST using inorder traversal Maintain: Previous value Current count Maximum frequency Update result list whenever a new maximum frequency is found Key Learning This problem highlights how leveraging tree properties can help optimize solutions. Instead of using extra space (like hashmaps), we used traversal behavior to achieve an efficient solution. Conclusion Understanding the underlying structure of data (like BST properties) is often more powerful than brute-force approaches. Smart traversal choices can significantly reduce space complexity and improve performance. #Day22 #100DaysOfCode #DSA #BinarySearchTree #Python #CodingJourney #LeetCode #ProblemSolving
To view or add a comment, sign in
-
-
💡 Cracking the Maximum Product Subarray Problem (Without Overcomplicating It) Today I worked on a classic DSA problem: Maximum Product Subarray — and found a simple yet powerful approach worth sharing. Most solutions focus on tracking max/min dynamically. But there’s a cleaner trick: 👉 Traverse the array from both directions (prefix & suffix) Why this works: Negative numbers can flip the product sign A single left-to-right pass might miss the optimal answer Scanning from both ends ensures we capture every possibility 🔁 Key Idea: Maintain two running products: Prefix (left → right) Suffix (right → left) Reset when product becomes 0 Track the maximum throughout ⚡ Complexity: Time: O(n) Space: O(1) Python code : https://lnkd.in/gZtCw9_i What I liked about this approach is its simplicity and elegance — no extra arrays, no complex state tracking. Sometimes, the best solutions aren’t the most complicated ones — just the most thoughtful. Have you tried solving this problem using a different approach? Would love to hear your thoughts 👇 #DataStructures #Algorithms #CodingInterview #Python #LeetCode #ProblemSolving Rajan Arora
To view or add a comment, sign in
-
-
🚀 Day 39/60 — LeetCode Discipline Problem Solved: Sqrt(x) Difficulty: Easy Today’s challenge was to compute the square root of a number without using built-in functions. Instead of brute force, I used Binary Search — a classic, elegant approach that narrows down the answer efficiently. 💡 Key Learnings: • Binary Search application beyond arrays • Handling edge cases (x < 2) • Avoiding overflow using conditions carefully • Finding floor value of square root • Optimized thinking over brute force ⚡ Performance: Runtime: 4 ms Like walking in a foggy path, I didn’t see the answer directly… But step by step— cutting the search space in half— the truth revealed itself. That’s the beauty of algorithms. #LeetCode #60DaysOfCode #DSA #BinarySearch #ProblemSolving #CodingJourney #Python #Consistency #TechGrowth
To view or add a comment, sign in
-
-
✅ Day 87 of 100 Days LeetCode Challenge Problem: 🔹 #2840 – Check if Strings Can be Made Equal With Operations II 🔗 https://lnkd.in/gY73RBb5 Learning Journey: 🔹 Today’s problem extended the previous one, allowing swaps between indices where the difference is even. 🔹 I observed that this again partitions the string into two independent groups: • Even indices (0, 2, 4, …) • Odd indices (1, 3, 5, …) 🔹 I extracted characters from even and odd positions separately for both strings. 🔹 Then, I sorted these groups and compared them between s1 and s2. 🔹 If both even-index groups and odd-index groups match, the strings can be made equal. Concepts Used: 🔹 String Manipulation 🔹 Index Grouping (Parity-based) 🔹 Sorting 🔹 Greedy Observation Key Insight: 🔹 Since swaps are allowed only between indices with even distance, characters can only move within their parity group. 🔹 Therefore, the problem reduces to checking if both parity groups have identical character distributions. Complexity: 🔹 Time: O(n log n) 🔹 Space: O(n) #LeetCode #Algorithms #DataStructures #CodingInterview #100DaysOfCode #SoftwareEngineering #Python #ProblemSolving #LearningInPublic #TechCareers
To view or add a comment, sign in
-
More from this author
-
🚀 Just Took My First Steps with the OpenAI Python API — Here's How Easy It Is!
HIMANSHU MAHESHWARI 2mo -
Beyond the Hype: A Practical Guide to Integrating AI & ML Into Your Projects
HIMANSHU MAHESHWARI 6mo -
🧠 Laravel Jobs & Queues vs Django Celery: A Backend Developer's Guide to Async Task Management 🚀
HIMANSHU MAHESHWARI 1y
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