One character change. 10,000x faster. When you check if something exists in a list: username in allowed_users_list Python checks every element. One by one. That's O(n). When you check if something exists in a set: username in allowed_users_set Python computes a hash and jumps directly to the answer. That's O(1). See the code 👇 With 10,000 users, the set version is roughly 10,000x faster for each lookup. The mental model: → List membership = Reading every name on a guest list → Set membership = Looking up a name in a phone book index In AI applications, this shows up everywhere: → Checking if a document is already in your vector store → Filtering duplicate embeddings → Validating allowed API keys The structure you choose isn't just about "what works." It's about what works at scale. This is adapted from my upcoming book, Zero to AI Engineer: Python Foundations. I share excerpts like this on Substack → https://lnkd.in/eFVTjauz #Python #Programming #DataStructures #AI #Performance
Python Set vs List: 10,000x Performance Boost
More Relevant Posts
-
Day 13 of #30DaysOfPython: Writing Cleaner Code with List Comprehension ⚡ Today’s focus was on writing more Pythonic code using List Comprehension. In Data Science, both speed and readability matter, and this feature helps achieve both at once. I built a small data cleaning pipeline that performs multiple transformations in a concise and efficient way. My practice included: 🧹 Filtering out noisy or invalid values from raw datasets 📐 Applying mathematical transformations across entire lists in one step 📖 Making the logic more readable by reducing repetitive loop structures It’s not just about shortening code — it’s about making it clearer, faster, and more professional. 📂 Check out the implementation here: https://lnkd.in/g_Q25442 #Python #CleanCode #DataScience #MachineLearning #AI #BuildInPublic #30DaysOfPython
To view or add a comment, sign in
-
Why Python remains the "Language of the Decade" in 2026 If you look at the tech landscape today, tools come and go. But Python? It only gets stronger. Whether I’m automating a repetitive task, cleaning a messy dataset, or building a predictive model, Python is the first tool I reach for. Here is why it’s still the undisputed king for professionals: ✅ It’s Human-Centric: The syntax is so close to English that you spend less time fighting the code and more time solving the actual business problem. ✅ The Ecosystem is Unbeatable: From Pandas for data to PyTorch for AI, if you have a problem, there is already a library to solve it. ✅ Versatility: One day you’re writing a script to organize files, the next you’re deploying a full-scale Machine Learning pipeline. In a world where AI is now writing code, Python has become the "bridge" language. It's the best way to communicate logic to machines and value to stakeholders. Question for my network: If you had to pick just one Python library that changed the way you work, which would it be? #Python #Programming #DataScience #Automation #ContinuousLearning #TechCommunity
To view or add a comment, sign in
-
Day 6 of #30DaysOfPython: When Data Should Stay Fixed 🔒 Today’s topic was Tuples. Unlike lists, tuples are immutable — once created, they cannot be changed. What seems like a limitation at first actually plays a crucial role in writing safe and reliable code. From a Machine Learning perspective, immutability helps protect critical data from accidental edits. I practiced using tuples to store fixed model specifications, such as: ⚙️ Hyperparameters that must remain constant during training 🖼️ Data dimensions to ensure consistency across the pipeline (e.g., 224 × 224) 🏷️ Metadata like labels and categories that shouldn’t be altered Understanding when to use a list for flexibility and a tuple for stability feels like an important step toward cleaner, more professional code. 📂 Explore today’s work here: https://lnkd.in/g_Q25442 #Python #MachineLearning #AI #BuildInPublic #LearningToCode #30DaysOfPython
To view or add a comment, sign in
-
Most Python “GenAI tutorials” teach syntax. Production systems fail for very different reasons. This cheat sheet focuses on the Python patterns that actually matter in real GenAI & LLM systems: • Tokenization → cost & latency • Embeddings → meaning for RAG • Vector search → retrieval quality • Chunking → recall vs noise • Context assembly → grounding • Prompt templates → versioning • Tool calling → controlled action • Agent loops → structure over autonomy • Memory → scoped state • Validation → safety & reliability • Evaluation → measurable quality • Caching → real cost savings If you’re building: – RAG pipelines – Agentic workflows – Production LLM services This isn’t “learning Python.” It’s using Python to ship GenAI systems that don’t break. 🔖 Save this you’ll reference it more than once. 💬 Comment “PART 2” if you want a deeper system breakdown next. #Python #GenAI #LLMs #RAG #AIEngineering #SystemDesign #MLOps
To view or add a comment, sign in
-
-
👀 How do you reverse a list using just ONE single line ❓ ❓ ❓ There are algorithms you can use to completely reverse a list. But if you need something short and simple: 🐍 Python has the Slicing technique❗ ❗ ❗ It is a powerful technique for extracting portions of sequences such as lists, strings, or tuples, using a concise and efficient syntax. nameList[ start : stop : step ] start => Index where the slice begins (included) stop => Index where the slice ends (not included). step => Increment between elements (optional, default is 1). If you wish to retrieve the entire list: 👉 nameList[ : ] If you want to REVERSE the ENTIRE list, just leave the start and stop empty and make the step negative. 👉 nameList[ : : -1] #Python #AI #Programming
To view or add a comment, sign in
-
-
With basic HTML + Python and a bit of help from AI, it’s become much easier to automate “small but annoying” tasks. That’s what really caught my attention especially since my major isn’t related to IT or software. In my free time, I’ve built a few automation scripts for myself and the results have been worth it: ✅ Less repetitive work ✅ Fewer manual errors ✅ More time for higher-value tasks AI has helped a lot by: - turning ideas into a working first version faster - spotting bugs and suggesting fixes - improving code so it’s cleaner and easier to read #Python #Automation #AI #VSCode #Productivity #LearningInPublic
To view or add a comment, sign in
-
Mojo in the Age of AI Agents Wes McKinney's recent post on "agent ergonomics" hit a nerve—especially his take on why Python struggles when AI agents become primary code authors. His thesis: agents need fast compile-test cycles, standalone binaries, and predictable performance. Python's dynamic nature (slow feedback, dependency hell, runtime surprises) works against reliable agent iteration. Go and Rust shine here, but come with a learning curve for Python-heavy teams. Enter Mojo from Modular (Chris Lattner and Tim Davis) —the missing piece I've been exploring in my GPU programming work. Mojo is a Python superset designed specifically for AI/systems programming. It keeps Python's syntax that agents already know, but adds: ✅ Static typing + borrow checking (compile-time safety) ✅ Sub-second compiles with no GIL or JIT unpredictability ✅ Direct GPU/TPU control (10x+ Python speedups) ✅ Seamless NumPy/Python interop (no ecosystem lock-in) The result? Agents can prototype in Python, then "mojofy" for production performance without retraining on Go's channels or Rust's ownership. I've written up how Mojo fits into Wes's landscape, with a side-by-side comparison to Go/Rust and a practical agent workflow example: 👉 https://lnkd.in/gKzzB8Va If you're building agent-driven data pipelines or AI workflows, Mojo might be the bridge to scalable code without a full rewrite. Curious what others think—are we really shifting from "human ergonomics" to "agent ergonomics" in language design? #Mojo #AIAgents #Python #PerformanceEngineering #DataScience
To view or add a comment, sign in
-
I used a simple Python chart today and it reminded me why accuracy can be misleading in machine learning. When a dataset is imbalanced (one class appears way more than the other), a model can look “good” just by predicting the majority class most of the time. Here’s what I did : 1. Plotted the class distribution 2. Checked what a “dumb baseline” accuracy would be if I always predicted the majority class 3. Decided to focus more on Precision, Recall, F1, and ROC-AUC instead of accuracy alone If 90% of the data is one class, a model can get ~90% accuracy while being useless for the minority class (which is often the important one). So, what I've learned is Before training any model, I now always do: Class distribution plot Baseline check Choose metrics that match the real goal ❓ Quick question In a high-stakes problem (fraud, health, risk), would you prioritise precision or recall — and why? #DataScience #MachineLearning #Python #DataVisualization #BuildInPublic
To view or add a comment, sign in
-
-
Stop wrestling with Python PDF libraries. It is time to add AI. 🛑 If you have ever tried to automate PDFs with Python, you know the struggle: the libraries are either too basic to be useful, or they require a "PhD in the PDF specification" just to get started. But we can flip the script by combining an industrial-strength library with Local AI. The Foundation: Pike PDF 🏗️ Forget the "awful compromise" of other libraries. Pike PDF is built on QPDF, a robust C++ engine used in professional tools. It handles the heavy lifting—fast web views, archival compliance, and complex merges—with a clean Python API. The Power-Up: Local AI Integration 🧠 The real game-changer is combining Pike PDF with local LLMs (like Ollama). Because the AI runs on your machine, your data never leaves your computer—a massive requirement for legal and financial documents. The "Intelligent" Workflow: 1. Extract: Pike PDF pulls raw text from messy reports. 2. Analyze: The Local AI generates an executive summary or extracts key data. 3. Rebuild: You automatically generate a new, smarter PDF variant (e.g., a summary version for executives). The Result: We are moving beyond just shuffling pages. We are turning "document chaos" into a structured, searchable knowledge base. Are you still manually summarizing reports, or is it time to build a pipeline? 👇 #Python #PikePDF #LocalAI #Ollama #Automation #DataScience #DocumentEngineering #FutureOfWork https://lnkd.in/g-SZSF3x
Python PDF Automation: Stop the Struggle & Add Local AI 🐍
https://www.youtube.com/
To view or add a comment, sign in
-
Python Built-in objects and expressions applies ditto to advanced objects and expressions. means: In math, just like: what I learnt 'a + b' does in basic math <-- equivalent to Py's built-in ob n exp Matrix A + Matrix B lingo in adv math also does same <-- adv obj n exp I mean If I know some basic expression like: a<b, then I can by intuition say Set A < Set B means Set A has fewer member than Set B. Lingo learnt on one kind of datatypes (be it advanced) or lingo learnt on one primitives; there are 90% chances that it works on other advanced datatypes. Py is written this way; so, question is not "How do I add these two things?" and start asking "Does this object support addition?" because you already know how to write it syntactically. the lingo philosophy of Math is here in Py as well.
To view or add a comment, sign in
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