Day 18 in the books 🔥 Regex keeps getting more interesting! Here’s your LinkedIn-style post for Day 18, matching the tone and structure of your earlier posts: Day 18/90 of #90DaysOfCode Today’s HackerRank challenge was about transforming strings using re.sub() in Python. The task focused on replacing logical operators in a string: Replace && with and Replace || with or But only when they appear between spaces (not inside other words or symbols). At first, I thought of using simple string replace methods. But then I realized this problem needed pattern-based replacement, not blind substitution. That’s where re.sub() came in. By using regex with lookahead and lookbehind, I was able to: Match only valid && and || operators Avoid replacing characters in the wrong places Cleanly transform the string in one pass Instead of manually scanning character by character, regex allowed me to describe what to replace using a pattern — and Python handled the rest. Key takeaway: re.sub() is powerful because it lets you modify strings based on patterns, not just exact matches. Understanding lookarounds ((?<= ) and (?= )) makes regex much more precise and safer for real-world text processing.
Day 18/90: Regex Challenge with re.sub() in Python
More Relevant Posts
-
Most developers using AI today don’t actually understand how Python works. They know how to write: - obj.attr But they don’t know what happens next. It’s not just dictionary lookup. Python runs a strict internal algorithm - Data descriptors - Instance __dict__ - Non-data descriptors - Class + MRO - __getattr__ That’s why: - @property works - Django fields override instance values - Methods bind automatically - Some attributes can’t be shadowed In the AI era, syntax is cheap. Understanding the object model is leverage. At TakoVibe, we intentionally publish content that goes deeper than surface-level tutorials. Because fundamentals compound. And depth is what makes you hard to replace. If you're serious about mastering core Python internals, this one’s for you: https://lnkd.in/gh6Qm2CN #python-internals #core-python #softwareengineering
To view or add a comment, sign in
-
-
Python in difference b/w single(_)underscore and double(__)underscore: We generally using for private variable that means when ever we used double reading (_) the variable over python interpreter treats with as the special variable to avoid name conflict with method in inner class. Pooja Chinthakayala Mam,Saketh Kallepu Sir,Uppugundla Sairam Sir. #difference between _and__ '''class Employee(): def __init__(self): self.name="lakshmi" self._mailid="lakshmi10@gmai.com" self.__salary=10000#private variable a=Employee() print(dir(a)) print(a.name) print(a._mailid) #print(a.__salary)error print(a._Employee__salary) output: lakshmi lakshmi10@gmai.com 10000''' '''class employee(): def __init__(self): self.name="bhavani" self._mailid="bhanu@gmail.com" self.__salary=12000 class employee1(): def __init__(self): self.name="sudha" self._mailid="sudha@gmail.com" self.__salary=12000 b=employee() print(dir(b)) print(b.name) print(b._mailid) print(b._employee__salary) b=employee1() print(dir(b)) print(b.name) print(b._mailid) print(b._employee1__salary)''' output:bhavani bhanu@gmail.com 12000 sudha sudha@gmail.com 12000
To view or add a comment, sign in
-
Would you like to causally intervene inside your LLM? This week on the Causal Python Newsletter @Aleksander Molak, I wrote about interventions in LLMs. When it comes to knowing what is going on inside a Large Language Model (LLM), Sparse Autoencoders (SAEs) are popular mechanisms that can discover features in the model’s representation space. This makes models more interpretable. In their new preprint, "Identifying Intervenable and Interpretable Features via Orthogonality Regularization", Moritz Miller, Florent Draye, and Bernhard Schölkopf present a PoC on how enforcing orthogonality in a SAE enables us to intervene in a feature and observe how the output changes in that respect while remaining invariant in every other aspect. The figure is taken from the paper and you can see how intervention correctness increases as the SAE’s features are enforced to be more distinct, while the model’s accuracy remains essentially unchanged. The parameter λ is the penalty for non-orthogonality in the loss function. Link to the paper in the comments. Subscribe to the Causal Python Newsletter to get more up-to-date information on Causality for free! https://causalpython.io/
To view or add a comment, sign in
-
-
Python Deep Dive | Understanding *args Like a Pro One small symbol… big impact. When we use *args in a Python function, where are the values actually stored? Many beginners guess list. Some even think it’s a generic collection. But the correct answer is: tuple ✅ 💡 Why tuple? When you define a function like this: def my_function(*args): print(type(args)) And call it like this: my_function(1, 2, 3) The output will be: <class 'tuple'> Python automatically collects all positional arguments into a tuple. ⸻ 🔍 Why did Python choose tuple instead of list? Because tuples are: • Immutable (cannot be modified) • Memory efficient • Faster than lists • Safer for internal function handling Since *args is meant to collect values, not modify them, immutability makes perfect design sense. ⸻ 🚀 Bonus Insight While: • *args → stores data in a tuple • **kwargs → stores data in a dictionary Understanding this difference is essential for writing clean, scalable, and flexible functions — especially in larger AI or backend systems. Small details like this separate someone who “writes Python” from someone who truly understands Python. #Python #Programming #AI #DataScience #CodingJourney #SoftwareEngineering #30DayChallenge
To view or add a comment, sign in
-
Just shipped a tiny regex engine in Python from scratch. 🎯 It supports literals, . wildcards, and the * operator using a recursive backtracking matcher, plus a full test suite and docs so you can see exactly how it works under the hood. I also wrapped it in some creative worldbuilding around “Pattern Keys” — forbidden codes that unlock hidden meaning in text — because learning hits different when you mix algorithms with imagination. This project was a deep dive into how regex engines actually work, how backtracking behaves in practice, and how to design clean, readable code instead of “magic.” What’s one algorithm you think every engineer should implement at least once? 👇 https://buff.ly/zY2K4yZ #Python #Regex #Algorithms #Coding #SoftwareEngineering #CreativeCoding #Backtracking
To view or add a comment, sign in
-
#MemoryManagement Recently, I tried to go deeper into how #Python manages memory, especially when working with lists, arrays, and large datasets in machine learning. A simple example highlights why this matters: When we write list1 = [[1, 2, 3], 4, 5] and then list2 = list1, Python does not create a new list — both variables reference the same object in memory. As a result, modifying one will also modify the other. This is where understanding shallow vs deep copy becomes important: • Shallow copy (list2 = list1.copy()) creates a new outer container but still references the nested objects inside it. For example, if you create a shallow copy and then change the list inside the list (list2[0][0] = 100), the change will appear in both lists because the inner list is shared in memory. • Deep copy (list3 = copy.deepcopy(list1)) duplicates everything recursively, creating a fully independent object in memory. So if you modify the inner list after a deep copy, the original list remains unchanged. In machine learning workflows, where we often handle large datasets, feature matrices, or tensors, misunderstanding references can lead to: 1. unintended data modification 2. difficult-to-trace bugs 3. inefficient memory usage Writing reliable #ML code is not only about choosing the right algorithms — it also requires understanding what happens behind the scenes in memory. Small concepts like these can make a big difference when building scalable and efficient systems 🚀 #MachineLearning #DataScience #Python
To view or add a comment, sign in
-
Stop Using sort() Just to Check Order in Python I still see this pattern in production code: def is_sorted_bad(lst): return lst == sorted(lst) It works… but it’s inefficient. Python’s built-in sort (Timsort) runs in O(n log n) and creates a new list — just to answer a yes/no question. If your list has 1 million elements, that’s ~20 million comparisons and a full memory copy. All that… when you only need to check adjacent pairs. The Right Way (O(n) + Early Exit) def is_sorted(lst): return all(x <= y for x, y in zip(lst, lst[1:])) ✔ O(n) time ✔ Stops at first violation ✔ No unnecessary sorting ✔ Clean & Pythonic And if you're on Python 3.10+, itertools.pairwise() is even cleaner. What This Article Covers In my latest blog post, I break down: • 5 efficient O(n) methods • Non-decreasing vs strictly increasing • Descending checks • Edge cases (None, mixed types, duplicates) • When sort() is actually the right choice • NumPy & Pandas native solutions • Performance comparison table Plus real benchmarks and interview-ready explanations. If you're writing performance-sensitive Python — especially in data pipelines — this is worth knowing. Full article here: https://lnkd.in/giChyRRc Curious — how many times have you seen lst == sorted(lst) in real projects?
To view or add a comment, sign in
-
-
Ever needed to track file changes in real-time? With 𝘄𝗮𝘁𝗰𝗵𝗱𝗼𝗴, you can do that in Python easily. 𝘄𝗮𝘁𝗰𝗵𝗱𝗼𝗴 allows you to detect file creations, modifications, and deletions instantly. See below for a small example. -> 𝗙𝗶𝗹𝗲𝗦𝘆𝘀𝘁𝗲𝗺𝗘𝘃𝗲𝗻𝘁𝗛𝗮𝗻𝗱𝗹𝗲𝗿: Handles file system events like when a file is modified or deleted. -> 𝗢𝗯𝘀𝗲𝗿𝘃𝗲𝗿: Watches the directory for changes Check it out: github(dot)com/gorakhargosh/watchdog --- ♻️ Found this useful? Share it with another builder. ➕ For daily practical AI and Python posts, follow Banias Baabe.
To view or add a comment, sign in
-
-
𝗗𝗮𝘆 𝟭 𝗼𝗳 𝗟𝗲𝗮𝗿𝗻𝗶𝗻𝗴 𝗣𝘆𝘁𝗵𝗼𝗻 🐍 𝗙𝗼𝘂𝗻𝗱𝗮𝘁𝗶𝗼𝗻 > 𝗙𝗮𝗻𝗰𝘆 𝗧𝗼𝗼𝗹𝘀 Today I officially started my Python journey. I didn’t jump into AI. I didn’t touch frameworks. I focused only on fundamentals. 𝗧𝗼𝗽𝗶𝗰𝘀 𝗜 𝗖𝗼𝘃𝗲𝗿𝗲𝗱: • Variables • Data Types (int, float, string, boolean) • Type conversion • String indexing & slicing • String methods • Conditional statements (if, elif, else) • Lists & basic list methods • Tuples & immutability At first glance, Python looks simple. But once you start writing logic, you realize — simplicity doesn’t mean easy. 𝗣𝗿𝗼𝗯𝗹𝗲𝗺𝘀 𝗜 𝗦𝗼𝗹𝘃𝗲𝗱 (Only Using Today’s Topics) I avoided loops intentionally since I haven’t learned them yet. Here are some logic-based problems I solved: 1️⃣ Check whether a number is even or odd 2️⃣ Find the largest of two numbers 3️⃣ Determine if a number is positive, negative, or zero 4️⃣ Check if a year is a leap year 5️⃣ Categorize age (Child / Teen / Adult / Senior) 6️⃣ Reverse a string using slicing 7️⃣ Check if a string is a palindrome 8️⃣ Count vowels in a string 9️⃣ Remove spaces from a string 🔟 Find the largest number in a list What I noticed: Writing conditions correctly requires precision. Small logical mistakes break everything. Edge cases matter more than expected. Example: Leap year logic isn’t just “divisible by 4.” It’s: • Divisible by 4 • Not divisible by 100 • Unless divisible by 400 That level of detail separates casual learning from real understanding. 𝗞𝗲𝘆 𝗟𝗲𝗮𝗿𝗻𝗶𝗻𝗴𝘀 𝗙𝗿𝗼𝗺 𝗗𝗮𝘆 𝟭 ✔ Python is clean but unforgiving with logic ✔ Strings are immutable (you can’t modify characters directly) ✔ Lists are mutable, tuples are not ✔ Truthy and falsy values are important ✔ Writing clean conditional logic is a skill 𝗧𝗵𝗲 𝗥𝗲𝗮𝗹𝗶𝘁𝘆 Today was not about “knowing Python.” It was about building base-level logical thinking. Syntax is easy. Consistency is hard. Problem-solving is harder. Tomorrow: Loops + deeper logic building. This is step 1. Long journey ahead. #Python #LearningJourney #SoftwareDevelopment #Programming #BuildInPublic #DeveloperGrowth
To view or add a comment, sign in
-
Aah… I am at the crossroads - tried-and-true marriage (C++/Python) or solo act (Julia). For the past few months, I delved into many tools that act as a glue between C++ and Python, like nanobind, pybind11, SWIG, Boost.Python, etc. All of these looked good. This is the industry-wise power couple for performance and ease of use. Read on... Horns of the dilemma - C++ & Python binding or Julia - implementation of strategy design pattern in Julia... https://lnkd.in/gHsf_FMu
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