Day 34 of my #100DaysOfCode challenge 🚀 Today I worked on a Python program to find all possible substrings of a given string. A substring is a continuous sequence of characters within a string. The goal was to generate every possible substring using nested loops. What the program does: • Takes a string as input • Uses nested loops to generate substrings • Extracts substrings using string slicing • Stores all substrings in a list • Returns the list of all substrings How the logic works: •A function find_all_substrings(s) is defined •An empty list substrings is created to store results •The first loop selects the starting index i •The second loop selects the ending index j •Each substring is extracted using slicing: s[i:j+1] •The substring is appended to the result list •Finally, all substrings are returned Example: Input: "abc" Output: ['a', 'ab', 'abc', 'b', 'bc', 'c'] Another example: Input: "hello" Output: ['h', 'he', 'hel', 'hell', 'hello', 'e', 'el', 'ell', 'ello', 'l', 'll', 'llo', 'l', 'lo', 'o'] Why this approach works well: – Uses nested loops to explore all start–end positions – Demonstrates string slicing clearly – Time Complexity: O(n²) Key learnings from Day 34: – Understanding substring generation – Using nested loops effectively – Applying string slicing in Python – Strengthening string algorithm concepts #100DaysOfCode #Day34 #Python #PythonProgramming #StringAlgorithms #ProblemSolving #CodingPractice #Algorithms #LearnByDoing #ComputerScience #ProgrammingJourney #DeveloperGrowth #BTech #CSE #AIandML #VITBhopal #TechJourney
Python Substring Generation with Nested Loops
More Relevant Posts
-
Unlocking the Power of Strings in Python! 🐍✨ Today’s focus on my Python journey was all about understanding and manipulation—specifically, Strings. It’s incredible how much logic depends on effectively handling text data! Here are my key takeaways from today's deep dive: ✂️ String Slicing: Mastering the [start:stop:step] syntax. It feels like precision surgery for text data—extracting exactly what you need, whether it's a prefix, a suffix, or a reversed substring. 🚫 String Immutability (Mutation): A crucial realization! You can’t change a string in place. Trying to do word[0] = 'C' will throw an error. Understanding this forces you to think correctly about creating new modified strings instead of trying to mutate existing ones. 🛠️ String Methods: My toolbox just got a lot bigger. I explored powerful built-in functions like: .strip() for cleaning up whitespace. .replace() for quick swaps. .split() and .join() for converting between strings and lists. .upper(), .lower(), .capitalize() for formatting. Understanding these fundamentals is making my code cleaner and more efficient. Every day is a step closer to building complex applications! #Python #CodingJourney #Strings #DataManipulation #SoftwareDevelopment #ContinuousLearning #WebDev #Backend #ProgrammingFundamentals #CleanCode #LearningToCode
To view or add a comment, sign in
-
-
🚀 Day 1: The Foundation & The "Aha!" Moment Focus: Variables & Fundamentals Today, I officially wrote my first lines of Python after a long time, and let’s just say… it was a beautifully humbling experience. 😅 I realized that even the "simplest" tasks—like adding numbers or printing a sentence—require total precision. Python is gentle until you forget a single quote mark, and then it’s game over! What I tackled today: The Execution Flow: Understanding how Python reads code from top to bottom. The Power of Variables: They’re essentially just containers, but naming them is an art form. The Rules: Learned why (my_var) works, but (2_var) breaks everything. Data Types: Realizing that 10 (integer) and "10" (string) might look the same to us, but they are worlds apart to a computer. It’s exciting, a little frustrating, and 100% worth it. 😁 #Python #Day1 #LearningToCode #TechBeginner #CodingFromScratch
To view or add a comment, sign in
-
-
Part II of my beginner's guide on building clean Python ML/AI projects is out! 🏗️ A codebase without strict rules inevitably turns into an inconsistent mess. But with properly configured static code analyzers, you can block bad code before it's even committed. This article is primarily tailored for Data Scientists and ML Engineers - SWE colleagues already know these basics inside out entirely I suppose :) . Here is the essential toolkit I cover: 🔹 Linting & Formatting: Catching Python anti-patterns at lightning speed. 🔹 Type Checkers: Why they are crucial (and some code quirk example from HuggingFace Transformers library). 🔹 Pre-commit & CI/CD: How to enforce strict checks pipeline to ensure messy code never reaches your main branch. Links to the full article: 🔗 Medium (EN): https://lnkd.in/dXTA7jQb 🔗 Substack (EN): https://lnkd.in/dwDmY6cK 🔗 Teletype (RU): https://lnkd.in/dG7hfTwK #Python #MLOps #MachineLearning #CleanCode #StaticAnalysis #Ruff #mypy #ty #Pyright #Pyrefly
To view or add a comment, sign in
-
Day 2 of my LeetCode journey 🚀 Today’s problem: Group Anagrams This challenge was all about grouping strings that share the same characters. I approached it using a dictionary + hashing strategy in Python. For each word, I sorted its characters and used that as a key (converted into a tuple), ensuring all anagrams map to the same bucket. Here’s the core logic I implemented: ▪️Traverse the list of strings ▪️Sort each string → convert to tuple → use as dictionary key ▪️Append original string to the corresponding group ▪️Finally, return all grouped values This approach keeps the implementation clean and scalable. Time Complexity: ▪️Sorting each string takes O(k log k) (where k = length of string) ▪️For n strings → O(n * k log k) overall Space Complexity: ▪️O(n * k) for storing grouped anagrams A solid step forward in understanding how hashing + transformations can simplify complex grouping problems. Staying consistent and leveling up daily 💪 #LeetCode #Day2 #Python #DSA #CodingJourney #ProblemSolving
To view or add a comment, sign in
-
-
Day 40 of my #100DaysOfCode challenge 🚀 Today I implemented the Merge Sort algorithm in Python. Merge Sort is a powerful divide-and-conquer algorithm that divides the list into smaller parts, sorts them, and then merges them back together. What the program does: • Takes an unsorted list as input • Recursively divides the list into halves • Sorts each half separately • Merges the sorted halves into a final sorted list How the logic works: • If the list has 1 or 0 elements, it is already sorted (base case) • The list is divided into two halves using the middle index • Each half is recursively sorted using merge_sort() • A helper function merge() combines the two sorted halves • Elements are compared and merged in sorted order • Remaining elements are appended after comparison Example: Input: [38, 27, 43, 3, 9, 82, 10] Output: [3, 9, 10, 27, 38, 43, 82] Why Merge Sort is powerful: – Time Complexity: O(n log n) – Efficient for large datasets – Stable sorting algorithm – Widely used in real-world applications Key learnings from Day 40: – Understanding divide-and-conquer strategy – Writing recursive functions – Merging sorted arrays efficiently – Moving towards advanced DSA concepts #100DaysOfCode #Day40 #Python #PythonProgramming #MergeSort #SortingAlgorithms #DataStructures #Algorithms #DivideAndConquer #ProblemSolving #CodingPractice #InterviewPrep #BTech #CSE #AIandML #VITBhopal #TechJourney
To view or add a comment, sign in
-
-
Ever tried to "fix" a value inside a `for` loop while zipping, only to find the original list unchanged? 🤔 Let's break down why. This is a classic Python iterator deep dive. When you zip lists, you create an iterator yielding tuples. The loop variable is just a reference to the current tuple element, not a pointer back into the list. **Key Mechanics:** - `zip()` produces an immutable tuple for each iteration. - Reassigning the loop variable simply points that variable to a new object; it does not mutate the original list. - The loop variable is a local name within the loop's scope, separate from the list's indices. **Takeaway:** To modify the original list, you need to access it by index, or use a list comprehension/map. Direct assignment to the iteration variable only rebinds the name. Understanding this distinction between names, references, and mutability is crucial for mastering Python's data model. It’s not a bug—it’s a feature of clean, predictable iteration. #Python #ProgrammingLogic #MorningCode #SoftwareEngineering #TechDeepDive What’s a similar "aha!" moment you’ve had with iterators or variable scoping?
To view or add a comment, sign in
-
Day 7 of my 100 Days of Code challenge 🚀 Today I built a Movie Recommendation System using Python, Pandas, Scikit-learn, and Streamlit 🎬 This project recommends similar movies based on genre using content-based filtering and cosine similarity. What I learned from this project: How recommendation systems work at a basic level How to convert text data into vectors using CountVectorizer How to use cosine similarity to find similar items How to deploy a Streamlit app How to debug a real deployment issue related to file paths It was a simple project, but it gave me a practical understanding of how recommendation logic works behind the scenes. 🔗 Live Demo: https://lnkd.in/dW8bTgzE 💻 GitHub Repo: https://lnkd.in/g6mgQ7qY Every small project is helping me understand concepts better and build confidence step by step. #100DaysOfCode #Python #MachineLearning #DataScience #Streamlit #ScikitLearn #AI #LearningInPublic #CodingJourney
To view or add a comment, sign in
-
-
Day 42 of my #100DaysOfCode challenge 🚀 Today I worked on a Python program to find the K-th largest element in an array. This is a common problem in coding interviews and helps build understanding of sorting and indexing. What the program does: • Takes an array and a value k as input • Sorts the array in descending order • Returns the k-th largest element • Handles duplicate values correctly How the logic works: • The array is sorted in descending order using sorted() • Since Python uses 0-based indexing,the k-th largest element is at index k-1 • The element at index k-1 is returned as the result Example: Input: Array: [3, 2, 1, 5, 6, 4] k = 2 Output: 5 (2nd largest element) Another example: Input: Array: [3, 2, 3, 1, 2, 4, 5, 5, 6] k = 4 Output: 4 Why this approach works: – Simple and easy to implement – Uses built-in sorting for reliability – Time Complexity: O(n log n) Key learnings from Day 42: – Understanding sorting in descending order – Working with indexing (k-1) – Solving common interview problems – Handling duplicates in arrays #100DaysOfCode #Day42 #Python #PythonProgramming #Arrays #Sorting #Algorithms #DataStructures #ProblemSolving #CodingPractice #InterviewPrep #LearnByDoing #ProgrammingJourney #DeveloperGrowth #BTech #CSE #AIandML #VITBhopal #TechJourney
To view or add a comment, sign in
-
-
INSTEAD OF WASTING TIME AND TRYING TO GET FIGURES. WHY NOT USING CODE?? Sometimes, lecturers or organizations need to generate different sets of questions for multiple candidates, especially when working with matrices. However, this often requires a lot of manual effort and can be time-consuming. Why not simplify the process using NumPy in Python? With just a few lines of code, you can easily generate multiple variations of matrix-based questions efficiently and save valuable time. #randint is an inbuilt function of the random module of numpy #Syntax: np.random.randint(start, stop (rows, columns)) a=np.random.randint(2,30, (3,3)) b=np.random.randint(2,30, (3,3)) c=np.random.randint(2,30, (3,3)) d=np.random.randint(2,30, (3,3)) e=np.random.randint(2,30, (3,3)) #DataScience #Python #NumPy #Education #Automation
To view or add a comment, sign in
-
-
LeetCode POTD 💫: Trying to be consistent with POTDs 🫠 Description: You are given two strings, str1 and str2, of lengths n and m, respectively. A string word of length n + m - 1 is defined to be generated by str1 and str2 if it satisfies the following conditions for each index 0 <= i <= n - 1: -> If str1[i] == 'T', the substring of word with size m starting at index i is equal to str2, i.e., word[i..(i + m - 1)] == str2. -> If str1[i] == 'F', the substring of word with size m starting at index i is not equal to str2, i.e., word[i..(i + m - 1)] != str2. Return the lexicographically smallest possible string that can be generated by str1 and str2. If no string can be generated, return an empty string "". Here's my solution: https://lnkd.in/g6B2-GWz #Python #DSA #Leetcode #DailyChallenge
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