𝗗𝗮𝘆 𝟭𝟰: 𝗦𝗲𝘁𝘀 𝗶𝗻 𝗣𝘆𝘁𝗵𝗼𝗻 🐍 𝗦𝗲𝘁𝘀: 🔹 Sets are unordered collections of items 🔹 Elements are unique (no duplicate values) 🔹 Items are separated by commas and enclosed in curly brackets { } 🔹 Sets do not maintain order 𝗖𝗿𝗲𝗮𝘁𝗶𝗻𝗴 𝗮 𝗦𝗲𝘁: 🔹 s = {1, 2, 3} 🔹 Use set() to create an empty set : s = set() ⚠️ {} creates an empty dictionary, not a set 𝗦𝗲𝘁 𝗢𝗽𝗲𝗿𝗮𝘁𝗶𝗼𝗻𝘀: 1️⃣𝗨𝗻𝗶𝗼𝗻 (|) → combines elements 2️⃣𝗜𝗻𝘁𝗲𝗿𝘀𝗲𝗰𝘁𝗶𝗼𝗻 (&) → common elements 3️⃣𝗗𝗶𝗳𝗳𝗲𝗿𝗲𝗻𝗰𝗲 (-) → elements in one set but not the other 4️⃣𝗦𝘆𝗺𝗺𝗲𝘁𝗿𝗶𝗰 𝗗𝗶𝗳𝗳𝗲𝗿𝗲𝗻𝗰𝗲 (^) → elements not common 📝Important Notes: 🔹 Sets do not support indexing or slicing 🔹 Elements must be immutable (int, string, tuple) Building strong Python fundamentals, one concept at a time 🚀 #Python #Tuples #LearningPython #LearningInPublic #AspiringDataScientist #Consistency
Python Sets: Unordered Collections and Operations
More Relevant Posts
-
Headline: Stop writing loops to clean your data. 🛑 One of the most common tasks in Python is handling duplicate entries. While you could write a for-loop with a conditional check, there’s a much faster, more "Pythonic" way to do it: Sets. Sets are unordered collections of unique elements. By casting your list to a set, Python handles the heavy lifting of deduplication instantly. Why use this? ✅ Cleaner, more readable code. ✅ Better performance for large datasets. ✅ Built-in membership testing (O(1) complexity). How are you using Sets in your current workflow? Let’s discuss below! 👇 #PythonProgramming #Pyspiders #CodingTips #SoftwareDevelopment
To view or add a comment, sign in
-
-
Pandas 3.0 is here! 🎉https://lnkd.in/dfAUP2bH - Copy-on-Write (CoW) fully implemented: SettingWithCopyWarning is gone ✅. No more debugging mysterious copies - chained assignments just work - pd.col() syntax: Clean column references in assign() and loc() without messy lambdas. E.g., df.assign(c=pd.col('a') + pd.col('b')) - Faster UDFs 🚀: No more "slow as molasses" user-defined functions - major perf boosts via better optimization (full Arrow backend didn't land, but it's solid) I made a Kaggle notebook to try https://lnkd.in/d-SsfryV #Pandas #DataScience #Python #DataAnalysis #MachineLearning
To view or add a comment, sign in
-
Weekly challenge 5: Recursion To understand recursion, you must first understand recursion. For Week 5 of my algorithm challenge, I decided to tackle a concept that trips up many beginners: Recursive Functions, using the classic Factorial problem. What is Recursion? Instead of using a standard `for` or `while` loop, a recursive function calls **itself** to solve a smaller piece of the problem. It keeps digging deeper until it hits a "Base Case" (the bottom), and then it passes the answers back up the chain. Think of it like a set of Russian nesting dolls. The Trade-off:** > While recursive code is extremely clean and mathematical, it uses more memory. Every time the function calls itself, it adds a new layer to the computer's **Call Stack**. If you forget your Base Case, your program crashes with a "Stack Overflow"! > > I added a visual trace to my Python script so you can literally see the Call Stack growing and shrinking in the console. Check the full code and console output on GitHub: https://lnkd.in/es5TzCUg #Python #Recursion #Algorithms #CodingChallenge #SoftwareEngineering #DataScience
To view or add a comment, sign in
-
𝐕𝐚𝐫𝐢𝐚𝐛𝐥𝐞𝐬 𝐬𝐨𝐮𝐧𝐝 𝐭𝐞𝐜𝐡𝐧𝐢𝐜𝐚𝐥. 𝐓𝐡𝐞𝐲’𝐫𝐞 𝐧𝐨𝐭. Body A variable is just a name for something you want to remember in your code. Instead of writing the same value again and again, you store it once and reuse it. That’s how programs stay clean and readable. 1. 𝑾𝒉𝒂𝒕 𝒂 𝒗𝒂𝒓𝒊𝒂𝒃𝒍𝒆 𝒊𝒔 A variable is a label that points to a value. Just like saving a contact name instead of memorizing a phone number. 2. 𝑯𝒐𝒘 𝒕𝒐 𝒂𝒔𝒔𝒊𝒈𝒏 𝒐𝒏𝒆 You create a variable using the equals sign: age = 20 This tells Python: store 20 under the name age. 3. 𝑹𝒆𝒂𝒍-𝒘𝒐𝒓𝒍𝒅 𝒆𝒙𝒂𝒎𝒑𝒍𝒆𝒔 name = "Alex" price = 2500 is_student = True These look like everyday things because that’s exactly what they represent. Once you get this, half of Python stops feeling confusing. 𝐃𝐫𝐨𝐩 𝐚 𝐯𝐚𝐫𝐢𝐚𝐛𝐥𝐞 𝐧𝐚𝐦𝐞 𝐲𝐨𝐮 𝐜𝐚𝐧 𝐜𝐫𝐞𝐚𝐭𝐞 𝐭𝐨𝐝𝐚𝐲. 𝐂𝐥𝐢𝐜𝐤 𝐭𝐡𝐞 𝐥𝐢𝐧𝐤 𝐭𝐨 𝐫𝐞𝐠𝐢𝐬𝐭𝐞𝐫 𝐟𝐨𝐫 𝐨𝐮𝐫 𝐌𝐋 𝐁𝐨𝐨𝐭𝐜𝐚𝐦𝐩 𝐢𝐧 𝐭𝐡𝐞 𝐜𝐨𝐦𝐦𝐞𝐧𝐭𝐬 𝐬𝐞𝐜𝐭𝐢𝐨𝐧. #PythonBeginners #LearnPython #CodingBasics #TechStudents #MachineLearningJourney #HEMPI
To view or add a comment, sign in
-
🚀 Day-53 of #100DaysOfCode 📊 NumPy Practice – Conditional Array Modification Today I practiced conditional filtering using NumPy. 🔹 Concepts Practiced: ✔ Boolean indexing ✔ Conditional replacement ✔ Vectorized operations ✔ Efficient array manipulation 🔹 Key Learning: Using boolean indexing (a[a < 0] = 0) allows fast and clean data transformation without loops — one of NumPy’s biggest advantages. Slowly building strong fundamentals in NumPy & Data Handling 💡🔥 #Python #NumPy #DataScience #ArrayManipulation #100DaysOfCode #LearnPython #CodingPractice #PythonDeveloper
To view or add a comment, sign in
-
-
Flagging outliers in time series is tricky. You need to decompose the series, calculate the residuals, choose a threshold, and then check if the results make sense. That's a lot of manual steps. And a lot of room for error. TimeCopilot handles it differently. You pass your data to detect_anomalies() and get: • Prediction intervals built with conformal methods • Anomalies flagged based on the confidence level you choose • Visualization with forecasts and anomalies together No separate tools. No manual calculations. 🚀Full tutorial: https://lnkd.in/ePEjshey #TimeSeries #AnomalyDetection #Python #DataScience
To view or add a comment, sign in
-
-
Day 2/100: Mastering Data Types and Logic Today was all about how Python handles information. I dived deep into the mechanics of data and mathematical operations. What I tackled today: Data Types: Understanding Integers, Floats, and Booleans. Subscripting: Pulling specific characters out of a string (like a pro!). The len() Function: Measuring the length of data. Type Conversion: Converting data (e.g., String to Integer) to make calculations possible. Math in Python: Using mathematical operators, the round() function, and assignment operators. Daily Project: Tip/Bill Calculator I created a program that calculates how much each person should pay when splitting a bill, including the tip. It’s a real-world tool built with just a few lines of code! Step by step, I'm getting more comfortable with the logic. 🚀 #Python #100DaysOfCode #DataTypes #CodingCommunity #SoftwareDevelopment
To view or add a comment, sign in
-
-
Weekly Challenge 4: Binary Search (Iterative). Why search harder when you can search smarter? Use Binary Search. Imagine looking for a word in a dictionary. Do you read every page from the beginning? No. You open it in the middle and decide: "Left or Right?". That is the essence of Binary Search, and it's the focus of my coding challenge for Week 4. The Implementation: I wrote a Python script (using NumPy) that generates a random environment to test the algorithm. Key Takeaway: While a simple loop (Linear Search) checks elements one by one ($O(n)$), Binary Search cuts the problem in half with every step ($O(\log n)$). Check out the trace in the console output below to see how few attempts it takes to find the target! 👇 📂 Full code on GitHub: https://lnkd.in/ezPaaiDM #Python #BinarySearch #Algorithms #CodingChallenge #DataStructures #Engineering
To view or add a comment, sign in
-
When I wrote Cookiecutter in 2013, I also created the first Cookiecutter template ever, a template for the ultimate Python package. 13 years later I've only just released v0.4.0. It took me this long because I didn't see a great use case for releasing it on PyPI until I started using uv/uvx heavily. Now you or your AI agent can get my boilerplate for a modern, fully-featured Python package by running one command: uvx cookiecutter-pypackage It comes with Audrey-level obsession over best practices, of course. I thought of making this release 1.0.0 but wanted to keep the version number humble. Be gentle and patient if you try it: I'm sure there will be a ton of embarrassing bugs that need fixing. There's also so much more that I want to do with it. https://lnkd.in/gBCJpz6P
To view or add a comment, sign in
-
Weekly Challenge 2: Sum Two Numbers Optimized. Yesterday I shared a Brute Force solution for the Two Sum problem. It worked, but it is slow(O(n^2)). Today, let's optimize it using a Hash Map. The strategy, instead of using nest loops to compare wverything against everything, we use memory to our advantage. As we iterate through the list, we calculate the "complement" (Target- Current) and ask "Have I seen this number before?" A highly efficient Python implementation of the 'Two Sum' problem using a Hash Map (Dictionary). Unlike the Brute Force approach, this script solves the problem in a single pass ($O(n)$) by storing visited numbers and checking for their complement instantly. Check the code on my GitHub: https://lnkd.in/eq5cQvWT #python #Optimization #Algorithms #DataStructures #BigO
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