glob finds files matching a pattern. Perfect for: - Batch processing - Data pipelines - File management One tip a day. Follow for more. #Python #DataScience 🐍
zip stops at the shortest list. zip_longest keeps going with fillvalue. Perfect for: - Data alignment - Padding incomplete data - CSV parsing with missing fields One tip a day. Follow for more. #Python #DataScience 🐍
pdb is a built-in Python debugger. Add this ONE line anywhere: import pdb; pdb.set_trace() Execution pauses and you can: - Inspect variables (p variable) - Step through code (n, s) - Continue or quit (c, q) One tip a day. Follow for more. #Python #DataScience 🐍
Replying to @staticmethod
@staticmethod = function in a class. No self, no cls. @classmethod = receives class (cls). Can create instances. Use classmethod for alternative constructors. Use staticmethod for utility functions. One tip a day. Follow for more. #Python #Coding 🐍
hasattr checks if attribute exists. getattr gets attribute with optional default. Perfect for: - Avoiding AttributeError - Dynamic method calls - Config files - Data parsing One tip a day. Follow for more. #Python #Coding 🐍
4
Stop using range(len()) to loop through lists. ❌ Ugly: for i in range(len(list)): print(i, list[i]) ✅ Clean: for i, item in enumerate(list): print(i, item) enumerate() gives you index AND value in one line. One tip a day. Follow for more. #Python #LearnToCode 🐍
1
2
setdefault sets a default value if key is missing. Perfect for: - Grouping data - Building indexes - Caching One tip a day. Follow for more. #Python #Coding 🐍
1
4
Counter is a dictionary for counting things. Manual way: counts = {} for item in items: counts[item] = counts.get(item, 0) + 1 Counter way: from collections import Counter counts = Counter(items) One tip a day. Follow for more. #Python #DataScience 🐍
4
The cycle: "I just need requests" *installs 47 libraries* 3 months later: "I don't remember what half of these do" But I MIGHT need them... 👕 This addiction is becoming a shirt. "import sanity" maybe. Link in bio. One tip a day. Follow for more. #Python #Coding
4
Flatten nested lists with chain.from_iterable(). Nested = [[1,2], [3,4], [5,6]] chain.from_iterable (nested) → [1,2,3,4,5,6] Why better than manual loops: - Faster (C implementation) - Cleaner - Memory efficient One tip a day. Follow for more. #Python #DataScience 🐍
3
Replying to @cached_property
@cached_property computes value ONCE, then caches it. Good for expensive ops. Example: class Report: @cached_property def sales_data(self): return database.query("SELECT * FROM sales") # once One tip a day. Follow for more. #Python #DataScience 🐍
1
💡 These exist because YOU voted and complained in replies. Every shirt comes from a real developer pain point. Next design ideas brewing: - "I'll comment later" - "import sanity" - "I am the bug" What's the next shirt I should make? #Python #Coding 👕
2
partial creates a new function with some arguments pre-filled. With partial: square = partial(power, exponent=2) Perfect for: - Specializing general functions - Callbacks with fixed parameters - Reducing repetition One tip a day. Follow for more. #Python #DataScience 🐍
2
The developer experience: Me: "I know exactly what I'm doing" My code: 💥 Me: "One small tweak" My code: 💥💥💥 Me: "I'll just rewrite it" My code: 💀 Me 3 hours later: "I wrote 3 lines" 👕 This is the most relatable shirt yet. Link in bio. #Python #Coding 🐍
2
__name__ == "__main__" lets code run ONLY when you execute the file directly (not when imported). Use it for: - Tests - Demos - CLI interfaces One tip a day. Follow for more. #Python #Coding 🐍
3