Published in Python in Plain English·Pinned5 Tricks to Condense Your Code into One Line in PythonThese tricks can allow you to write many functions in just one line. — If you want to write your Python functions in one line, here are 5 tips and tricks that you can use in your code. While there are some functions that are impossible to be written in one line, these 5 tricks can probably allow you to write many more functions…Python4 min read
Published in Towards Dev·Pinned4 Ways To Annoy Your Colleagues With Your Python CodeHere are 4 ways to write your code that will make your software engineer colleagues go “what the hell?” and give them a massive headache. 1) Using Weird Magic Methods Let’s say we need to add a and b together. The normal way x = a + b The annoying way x = a.__add__(b) This does the exact same thing as…Python5 min read
Published in CodeX·PinnedChecking If Maze Is Solvable In One Line Of PythonLet’s say we’re given a list of strings representing a maze: maze = [ "P---#", "###--", "----#", "-###-", "----X" ] P represents the player, and always starts at the top left X represents the reward, and is always at the bottom right - represents a path, which the player can…Python6 min read
Published in CodeX·PinnedAnother Python Question That Took Me Days To Solve As A BeginnerI started learning Python programming in university in 2017, and have come across a couple of weird practice questions that took me days to solve. One such question: A Python Question That Took Me Days To Solve When I Just Started 4 years ago in mid 2017, I took my first basic Python class in University. This class titled introduction to…medium.com Here, I’ll share another question that literally took me days to solve — well, it came up during a Python test and…Python5 min read
Pinnedif __name__ == “__main__” in Python Explained SimplyIf you just started learning Python, you’ve probably come across something like this: # stuff if __name__ == "__main__": # do stuff This article will attempt to explain as simply as possible what is happening here, and the situations where if __name__ == "__main__" is required. …Python4 min read
Published in Python in Plain English·1 day ago5 Python Questions 75% of You Can’t Solve in One Line of CodeSolutions to the questions that 75% of Python programmers can’t solve in one line of code. — This article contains the answers (one-liner functions) to my previously-written article: 5 Python Questions 75% Of You Probably Can’t Solve In One Line Of Code Being able to write code in one line probably won’t guarantee you a high-paying tech job, but it sure does feel…zl-liu.medium.com 1. Checking If A Number Is PrimePython3 min read
Published in Python in Plain English·4 days agoHow Using ‘yield’ Instead of ‘return’ Can Make Your Python Code FasterA quick demonstration of why sometimes using yield is better and can make your code run faster (especially when dealing with lots of data). — When we started learning Python, we were probably taught to use the return keyword in functions rather than yield. In this article, I’ll quickly demonstrate why sometimes using yield is better and can make your code run faster (especially when dealing with lots of data).Python4 min read
Published in Python in Plain English·6 days agoHow to Create a Class in Python Without Using the ‘class’ KeywordA guide on creating a class in Python without using the ‘class’ keyword. — Disclaimer — You probably won’t ever see this in real code. But messing around with code is fun, so let’s explore how we can define a class without using the class keyword. A Normal Dog Class class Dog: def __init__(self, name, age): self.name = name self.age = age def bark(self): print(f"Dog(name={self.name}, age={self.age}): woof")Python 33 min read
Published in Python in Plain English·Jun 18An Easy Python Code Snippet to Replace OutliersA guide on how to replace outliers in Python. — When performing data processing, we need to do something to outliers to protect our model from being completely screwed up. Here’s a simple Python code snippet that allows you to do just that. Our Dummy Dataset data = pd.DataFrame([ [87, 82, 85], [81, 89, 75]…Python3 min read
Jun 155 Python Questions 75% Of You Probably Can’t Solve In One Line Of CodeBeing able to write code in one line probably won’t guarantee you a high-paying tech job, but it sure does feel satisfying. Here are thus 5 Python questions that can usually be easily solved under normal circumstances. The catch — you need to solve it in one line of code. 1. Checking If A Number Is Prime …Python4 min read