Ever tried to sort a list and ended up with None? The logic looks correct: nums = [3, 1, 2] sorted_nums = nums.sort() print(sorted_nums) 👉 Output: None Why did it fail? In Python, there is a big difference between a Method that modifies an object and a Function that returns a new one. 1️⃣ .sort() is a Method: It modifies the original list "in-place." It doesn't need to return anything because the work is done directly on the original variable. 2️⃣ sorted() is a Function: It creates a brand-new list and leaves the original one exactly as it was. Use .sort() when you want to save memory and don't need the original order anymore. Use sorted() when you need to keep your original data safe and want a new sorted version. #Python #30DaysOfCode #BCA #LearningInPublic #Day22 #JECRC
Python sort() vs sorted() Method
More Relevant Posts
-
Day 5 of #30DaysOfPython ✅ Today I met two of Python's most powerful data structures. One of them already feels like home. The other? Slightly chaotic. Lists and dictionaries. Day 5. Lists made sense quickly — they're just ordered collections. I can store things, loop through them, sort them, slice them. Intuitive. Dictionaries? At first, the key-value pair concept felt abstract. The bug that got me today? I threw both strings and integers into the same list and tried to sort it. Python did not appreciate that. TypeError showed up like an old enemy. Day 5 done. 25 more to go! 👇 Lists vs dictionaries — when do you reach for one over the other? #Python #30DaysOfPython #DataStructures #StudentLife #AIML
To view or add a comment, sign in
-
-
Most implementations of the State pattern in Python look very “clean”. Lots of small classes. A base interface. One class per state. But if you’ve ever worked with one in a real project, you know the downside: transitions are scattered, behaviour is hard to see in one place, and adding new states often means touching multiple files. In today’s video, I rebuild the State pattern in a very different way. Instead of relying on inheritance, I make the state machine explicit as data and use decorators to define transitions. The result is a small, reusable engine where the entire flow becomes visible at a glance. If you’re interested in writing Python that’s easier to reason about and extend, this is a pattern worth understanding. 👉 Watch here: https://lnkd.in/e9Y3xGNF. #python #softwaredesign #designpatterns #statemachine #cleancode
To view or add a comment, sign in
-
-
Most implementations of the State pattern in Python look very “clean”. Lots of small classes. A base interface. One class per state. But if you’ve ever worked with one in a real project, you know the downside: transitions are scattered, behaviour is hard to see in one place, and adding new states often means touching multiple files. In today’s video, I rebuild the State pattern in a very different way. Instead of relying on inheritance, I make the state machine explicit as data and use decorators to define transitions. The result is a small, reusable engine where the entire flow becomes visible at a glance. If you’re interested in writing Python that’s easier to reason about and extend, this is a pattern worth understanding. 👉 Watch here: https://lnkd.in/eg22yEHR. #python #softwaredesign #designpatterns #statemachine #cleancode
To view or add a comment, sign in
-
-
Day 18 revision done. Operators. If/Else. Match statements. While loops. For loops. Not just reading through notes this time actually writing the code out, making mistakes, fixing them and doing it again until it felt natural. And honestly? It's working. The things that confused me the first time around are starting to make sense now. I finally get why // and % are different. I understand why indentation is not optional in Python. I know when to use a while loop vs a for loop. Revision isn't glamorous. There's no big aha moment. It's just you sitting down, doing the work and trusting that repetition builds confidence. And slowly it is making sense It is finally sticking and guess what I'm happy. Because Python is one of the most amazing tools used in the data space and I'm out here learning it on my own. Day 19 is next. Let's keep going. #Python #100DaysOfCode #SelfTaught #GrowthMindset #DataAnalysis #W3schools
To view or add a comment, sign in
-
📊 Comparing Two Outlier Removal Approaches in Python When cleaning datasets, how you remove outliers matters more than you think. I recently compared two common strategies: 1️⃣ Column-wise removal – Drop outliers sequentially, one column at a time. 2️⃣ Dataset-level removal – Flag all outliers across the entire dataset first, then remove them together. 🔍 What I found: The column-wise approach changes the IQR bounds after each removal, causing many non‑outlier rows to be wrongly filtered out (545 → 365 rows). The dataset-level approach respects original distributions, removes only true outliers (545 → 463 rows), and avoids over‑cleaning. ✅ Takeaway: Always identify outliers globally before removing them – your data will thank you. 📁 Used Python, pandas, IQR method, and a housing dataset. 🔗 Full code & notebook: https://lnkd.in/gheGYYEz #DataScience #Python #OutlierDetection #DataCleaning #Pandas #MachineLearning
To view or add a comment, sign in
-
You inherit a base class with twelve methods. Your subclass needs three. You implement the other nine as raise NotImplementedError and call it a day. That's the smell ISP is trying to prevent. Interface Segregation says clients shouldn't depend on methods they don't use. A fat interface forces every implementer to carry weight that doesn't belong to them, and every caller to reason about behavior that isn't relevant. ⚖️ In my latest article I break down what small interfaces look like in Python: Protocols, ABCs, and the practical line between "split this" and "you're over-engineering." 🧩 https://lnkd.in/eKw68T9S What's the worst case of NotImplementedError you've had to live with? 👀 #Python #SoftwareEngineering #SOLID #DataScience #CleanCode
To view or add a comment, sign in
-
I got tired of scrolling through messy file names… so I fixed it with a small Python script. While reading One Piece manga PDFs, the file names were all over the place: chapter-1112, one-piece-chapter-1222, onepiece-1123, OP-Chapter-1123… Finding the correct order every time was annoying. So I wrote a simple script that: Extracts the chapter number from any format Renames files into a consistent structure Automatically arranges them in readable order Nothing fancy just solving a small personal problem and saving time. This reminded me: You don’t always need big projects. Even small scripts that remove friction from your daily life are worth building. Clean input → Clean output → Peace of mind 😌 #Python #LearningByDoing #Automation #OnePiece #Coding
To view or add a comment, sign in
-
-
Python Clarity Series – Episode 23 Topic: Floating Point Precision Issue 🤯 Why does this happen? print(0.1 + 0.2) Output: 0.30000000000000004 ❗ 👉 This is NOT a Python bug. It’s due to how floating-point numbers are stored in binary. 💡 Fix (when needed): round(0.1 + 0.2, 1) Output: 0.3 💡 Concept: Computers approximate decimal values internally. Important in: ✔ Financial calculations ✔ Data Science Don’t ignore this. #PythonConcepts #FloatingPoint #RealWorldCoding #python #clarity
To view or add a comment, sign in
-
-
Copying vs Reference 🐍 I thought this would create a copy: b = a It didn’t. a = [1, 2, 3] b = a b.append(4) print(a) 👉 [1, 2, 3, 4] Both variables point to the same list. No copy was made. In Python, variables are just labels, not containers. When you use =, you aren’t duplicating data, you’re just giving the same memory address a second name. To actually copy: b = a.copy() Looks the same. Behaves completely differently. 💡 And also: .copy() only goes one layer deep and that's why we need deep copy. ➡️ Assignment ≠ Copy Day 17/30 #Python #30DaysOfCode #SoftwareEngineering
To view or add a comment, sign in
-
-
Python Series — Day 3 🧠 Let’s level it up a bit 👇 What will be the output of this code? def modify_list(lst): lst.append(4) a = [1, 2, 3] modify_list(a) print(a) Options: A. [1, 2, 3] B. [1, 2, 3, 4] C. Error D. None Think carefully 👀 (Hint: It’s not about functions… it’s about how Python handles data) Drop your answer 👇 Answer tomorrow 🚀 #Python #CodingChallenge #LearningInPublic #DataEngineering #Tech
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