Day 26 of my #100DaysOfCode challenge 🚀 Today I worked on a Python program to find the intersection of two arrays (lists). The goal was to identify the elements that appear in both arrays using Python’s set operations. What the program does: • Takes two lists as input • Converts the lists into sets • Finds the common elements between them • Demonstrates two ways to compute intersection • Prints the intersection result How the logic works: 1)Two lists (arr1 and arr2) are defined 2)Both lists are converted into sets using set() 3)Intersection is calculated using the .intersection() method 4)The same result is also computed using the & operator 5)The resulting set is converted back into a list and printed Example: Input: Array 1:[1, 2, 3, 4, 5] Array 2:[4, 5, 6, 7, 8] Output: Intersection:[4, 5] Why using sets is powerful: – Removes duplicate values automatically – Faster lookup operations – Time Complexity around O(n) Key learnings from Day 26: – Understanding set operations in Python – Using .intersection() vs & operator – Writing efficient list comparison logic – Strengthening data structure knowledge #100DaysOfCode #Day26 #Python #PythonProgramming #SetOperations #DataStructures #Algorithms #ProblemSolving #CodingPractice #LearnByDoing #ComputerScience #InterviewPrep #BTech #CSE #AIandML #VITBhopal #TechJourney
Python Set Operations: Intersection of Two Arrays
More Relevant Posts
-
Day 33 of my #100DaysOfCode challenge 🚀 Today I worked on a Python program to implement a custom version of the len() function. Instead of using Python’s built-in len() function, I created my own function to count the number of elements in an iterable. What the program does: • Takes any iterable as input (list, string, tuple, etc.) • Iterates through each element • Counts elements one by one • Returns the total length How the logic works: 1)A function manual_len(iterable) is defined 2)A variable count is initialized to 0 3)The program loops through each element in the iterable 4)For every element, the counter is incremented by 1 5)After the loop ends, the final count is returned Example: List:[1, 2, 3, 4, 5] Output: Length = 5 String: "Hello, Colab!" Output: Length = 13 Tuple: (10, 20, 30) Output: Length = 3 Why this is useful: – Helps understand how built-in functions work internally – Demonstrates iteration over different data types – Strengthens understanding of iterables in Python Key learnings from Day 33: – Implementing built-in functionality manually – Working with iterables in Python – Understanding loops and counters – Strengthening Python fundamentals #100DaysOfCode #Day33 #Python #PythonProgramming #Algorithms #ProblemSolving #CodingPractice #LearnByDoing #ProgrammingJourney #DeveloperGrowth #ComputerScience #InterviewPrep #BTech #CSE #AIandML #VITBhopal #TechJourney
To view or add a comment, sign in
-
-
Day 32 of my #100DaysOfCode challenge 🚀 Today I worked on a Python program to implement a custom version of the isdigit() function. Instead of using Python’s built-in method, I created my own function to check whether a string contains only numeric digits. What the program does: • Takes a string as input • Checks each character in the string • Verifies whether it lies between '0' and '9' • Returns True if all characters are digits • Returns False otherwise How the logic works: 1)The function first checks if the string is empty 2)If it is empty, it returns False 3)The program iterates through each character in the string 4)It checks whether the character falls within the range '0' to '9' 5)If any character fails this condition, the function returns False 6)If all characters satisfy the condition, the function returns True Example: Input: "123" Output: True Input: "123a" Output: False Input: "-1" Output: False Input: "0" Output: True Why this is useful: – Helps understand how built-in functions work internally – Uses ASCII character comparison – Strengthens string validation logic Key learnings from Day 32: – Implementing built-in functionality manually – Understanding ASCII-based comparisons – Writing validation logic for strings – Strengthening Python fundamentals #100DaysOfCode #Day32 #Python #PythonProgramming #StringValidation #Algorithms #ProblemSolving #CodingPractice #LearnByDoing #ComputerScience #ProgrammingJourney #DeveloperGrowth #BTech #CSE #AIandML #VITBhopal #TechJourney
To view or add a comment, sign in
-
-
#Day 47 of My Python & DSA Journey Today I solved the “Check if Binary String Has at Most One Segment of Ones” problem on LeetCode. 🔍 Problem Overview: Given a binary string containing only 0s and 1s, the task is to determine whether the string contains at most one continuous segment of 1s. If multiple separated segments of 1s exist, the result should be False. 🧠 Approach: I iterated through the string and tracked how many times a new segment of 1s starts. Whenever a 1 appears either at the beginning of the string or immediately after a 0, it indicates the start of a new segment. If more than one such segment is found, the condition fails. ⚡ Key Takeaways: • Strengthened understanding of string traversal • Practiced pattern recognition in binary strings • Improved logical problem-solving using Python 📊 Complexity: • Time Complexity: O(n) • Space Complexity: O(1) Consistently solving problems helps me improve my algorithmic thinking and coding efficiency every day. Looking forward to learning more and solving tougher challenges ahead! Under the Guidance of : Rudra Sravan kumar and Manoj Kumar Reddy Parlapalli #Day47 #Python #LeetCode #DataStructures #Algorithms #CodingJourney #ProblemSolving #100DaysOfCode
To view or add a comment, sign in
-
-
🐍 Day 12 of My 30-Day Python Learning Challenge Today I worked on a real-world concept: File Handling in Python. 📌 Problem: Read a file and count how many words it contains. 📌 Code: file = open("sample.txt", "r") content = file.read() words = content.split() print(len(words)) file.close() 📌 Output: Total number of words in the file 💡 Why this matters? File handling is used in: • Data processing • Log analysis • Backend development 📊 Quick Question What will happen if the file does NOT exist? A) Error B) Empty output C) None D) 0 Answer tomorrow 👇 #Python #FileHandling #CodingJourney #LearningInPublic #SoftwareDeveloper
To view or add a comment, sign in
-
Python Clarity Series – Episode 19 Topic: map() vs Loop 📌 Two ways to apply a function to a list. Traditional loop: nums = [1,2,3,4] squares = [] for i in nums: squares.append(i*i) Pythonic way: nums = [1,2,3,4] squares = list(map(lambda x: x*x, nums)) 👉 map() applies a function to every element. Result: [1, 4, 9, 16] 💡 Clarity Thought: Loop → easy to understand map() → shorter and functional style Both are correct. Python gives multiple ways to solve problems. Understanding both improves coding flexibility. #PythonLearning #CodingEfficiency #FutureDevelopers
To view or add a comment, sign in
-
-
Headline: Making Health Data Actionable with Python! 🐍 I recently worked on a calorie requirement calculator that uses List Comprehension to streamline data processing. By combining conditional logic with Python’s concise syntax, I was able to map out nutritional needs across different age brackets and genders effectively. Key takeaways from this build: Using range() and list comprehension for efficient iterations. Implementing multi-level if-elif statements for precise data output. Practicing clean, readable code in Jupyter Notebook. Always looking for ways to make complex data simpler through code! Muhammad Rafay Shaikh #Python #DataScience #Coding #ListComprehension #JupyterNotebook #WebDevelopment
To view or add a comment, sign in
-
-
🚀 Day 3 of Learning Python Today was all about writing smarter and more efficient code: ✅ `filter()` function ✅ `lambda` functions ✅ `return` statement The `filter()` function helped me understand how to extract specific data from a list based on conditions. With `lambda` functions, I learned how to write short, one-line functions — super useful for quick operations without defining full functions. And the `return` statement showed me how functions give back results, making them reusable and powerful. Each concept is small on its own, but together they really change how you think about problem-solving in code. Staying consistent and building every day 💪 #Python #CodingJourney #LearningInPublic #100DaysOfCode #TechSkills #StudentDeveloper
To view or add a comment, sign in
-
🚀 Day 50 of My Python Journey Today I solved Complement of Base 10 Integer on LeetCode. 🔍 Problem Overview: The task is to find the bitwise complement of a given base-10 integer. The complement is obtained by flipping all bits in its binary representation — changing every 0 to 1 and every 1 to 0. 🧠 Approach: 1️⃣ Convert the integer into its binary representation. 2️⃣ Traverse the binary string and flip each bit (1 → 0, 0 → 1). 3️⃣ Convert the resulting binary string back to a decimal integer. ⚡ Key Learnings: • Practiced binary representation and bit manipulation • Improved understanding of number systems (binary ↔ decimal) • Strengthened string manipulation and logical thinking in Python 📊 Complexity: • Time Complexity: O(n) • Space Complexity: O(n) Under the Guidance of : Rudra Sravan kumar and Manoj Kumar Reddy Parlapalli #Day50 #Python #LeetCode #DataStructures #Algorithms #CodingJourney #ProblemSolving #100DaysOfCode 🚀
To view or add a comment, sign in
-
-
🚀 Day 48 of My Python & DSA Journey Today I solved Find Unique Binary String on LeetCode. 🔍 Problem Overview: We are given an array of unique binary strings of length n. The goal is to generate another binary string of the same length that does not exist in the given list. 🧠 Approach: I applied a clever idea inspired by Cantor’s Diagonalization. By iterating through the list and flipping the diagonal bits (changing 1 → 0 and 0 → 1), we can construct a new binary string that is guaranteed to differ from every given string at least at one position. This ensures the generated string is unique. ⚡ Key Takeaways: • Learned about the Diagonal Method for generating unique strings • Improved string manipulation and logical thinking in Python • Strengthened understanding of problem-solving techniques in algorithms 📊 Complexity: • Time Complexity: O(n) • Space Complexity: O(n) Under the Guidance of : Rudra Sravan kumar and Manoj Kumar Reddy Parlapalli #Day48 #Python #LeetCode #DataStructures #Algorithms #CodingJourney #ProblemSolving #100DaysOfCode 10000 Coders
To view or add a comment, sign in
-
-
🚀 Day 3 of Learning Python Today was all about writing smarter and more efficient code: ✅ `filter()` function ✅ `lambda` functions ✅ `return` statement The `filter()` function helped me understand how to extract specific data from a list based on conditions. With `lambda` functions, I learned how to write short, one-line functions — super useful for quick operations without defining full functions. And the `return` statement showed me how functions give back results, making them reusable and powerful. Each concept is small on its own, but together they really change how you think about problem-solving in code. Staying consistent and building every day 💪 #Python #CodingJourney #LearningJourney#30DaysOfCode #TechSkills #Deeper Learning # Leet code
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