From simple methods to the ultimate weapon

5 Ways To Remove Spaces of A Python String
5 Ways To Remove Spaces of A Python String

Handling strings, especially messy strings, is the daily work of Python developers and data scientists. One of the most common symptoms of a messy string is that there are unnecessary or duplicate spaces in it.

Fortunately, no matter how messy a string is and how complicated a scenario is, Python can provide us a corresponding way to remove spaces as we like.

This article will introduce 5 different methods to remove spaces in a messy Python string based on different scenarios and requirements. After reading, you can choose the most appropriate way for your code. …


From static to sticky locations

CSS Position: Locate Your HTML Elements Like a Guru
CSS Position: Locate Your HTML Elements Like a Guru
Photo by Jamie Street on Unsplash

CSS is powerful.

Sometimes, just a special CSS property is enough to do something amazing. The position property is one of the magic properties.

For example, if we have a few pictures on a page:

<div><img src="p1.jpg"></div>
<div><img src="p2.jpg"></div>
<div><img src="p3.jpg"></div>
<div><img src="p4.jpg"></div>
<div><img src="p5.jpg"></div>

How can implement a stacking effect for them like the following?


Box your HTML elements up like a guru

CSS Box Model: 5 Steps To Turn an Element into a Box
CSS Box Model: 5 Steps To Turn an Element into a Box
Photo by Sahand Babali on Unsplash

The box model, which is mentioned frequently in front-end developers’ interviews, is an important concept of CSS. After all, to design the layout of a page is to manage the boxes on it.

A box is a concept. There is no original HTML tag named <box>.

It’s combined with 4 parts: content, padding, border and margin. The HTML element in a box is the content. We can control these parts precisely by CSS to decorate and manipulate the element.


A feature that makes native CSS super powerful

5 Levels of Using CSS Variables
5 Levels of Using CSS Variables
Photo by Eleonora Patricola on Unsplash

To declare and apply a variable within CSS is a common usage requirement. Especially for big projects, it’s totally tedious to write the same CSS value many times. Not to mention it’s hard to handle these values conveniently by JavaScript.

In the early days, the native CSS is not as powerful as expected, and we have to use one of the CSS preprocessors, such as SASS or LESS, to define variables in CSS.

Fortunately, since 2017, all major browsers support CSS variable syntax, it’s a feature that makes native CSS great again.

This article will introduce the usages of this…


To write workable code is easy, but to write readable code is hard.

10 Common Symptoms of Unreadable Code
10 Common Symptoms of Unreadable Code
Photo by Start Digital on Unsplash

Joel Spolsky, the founder of the Stack Overflow, has a famous saying, “It’s harder to read code than to write it.”

Unfortunately, it’s true. Reading other people’s code is our daily job as software engineers. If you work as an engineer for a long enough time, you’ve probably been pissed off by some poorly readable or even unreadable code.

This article summarises the 10 common symptoms of unreadable code. The ambition of this article is not only to remind you to avoid these bad practices. More importantly, I want to let you know that when you read or debug some…


The great point to show the evolution of JavaScript

4 Ways To Write For Loops in JavaScript
4 Ways To Write For Loops in JavaScript
Photo by Oliver Hale on Unsplash

JavaScript is evolving so fast in these years. If you are from other programming languages, you probably can’t believe that there are four ways to write just one for loop in JavaScript.

As Hegel said, “What exists is reasonable.” In the course of technological evolution, the power of the web becomes stronger and stronger. Therefore, the expectations for JavaScript, which is an inevitable language for modern web development, are also getting higher and higher.

The syntax of for loops is a good example. Developers found the old-fashion was not good enough, at least not for every using scenario. Some third-party…


Assign the expected values easily

5 Best Practices of Destructuring Assignments in Python
5 Best Practices of Destructuring Assignments in Python
Photo by Nick Fewings on Unsplash

Assigning values to variables is a basic operation of programming. Some programming languages, such as Python, have some syntax sugar to make the process more elegant.

Let’s see a simple example:

a, *mid, b = [1, 2, 3, 4, 5, 6]
print(a, mid, b)
# 1 [2, 3, 4, 5] 6

As shown above, with the help of one asterisk, the mid variable receives the items in the middle as a list. This is one of the destructuring assignment techniques in Python.

This article will introduce the major tricks of destructuring assignments in Python as 5 best practices. …


Make your JavaScript code much more elegant

3 Uses of the Three Dots in JavaScript
3 Uses of the Three Dots in JavaScript
Photo by Clay Banks on Unsplash

If you read any modern JavaScript programs, you probably will meet one thing many times — the ellipsis. It is just three dots (…) which was introduced by ES6. Looks very simple and unremarkable? However, it changed JavaScript a lot.

Let’s feel it by a simple example:

Now, we have a string called author as following:

let author = "Yang"

How can we convert this string to an array including all the characters?

In C or C++, we need to define an array at first and then use a for loop to iterate all characters and add them into the…


Release the superpower of Python as a dynamic language

The Eval Function in Python: A Powerful but Dangerous Weapon
The Eval Function in Python: A Powerful but Dangerous Weapon
Photo by Gioele Fazzeri on Unsplash

The eval function is a weapon to release the superpower of Python as a dynamic programming language.

Talk is cheap, let’s see it by a simple scenario:

On a normal working day, your boss came over to the software team and said,

“I need you guys to implement a function, which will receive two numbers a and b and a string op. The op, by the way, stands for an arithmetic operator, such as “+”, “-”, “*” and “/”. Your function needs to return the calculated result of a op b.”

Then he added another sentence,

“Don’t waste my time…


Level up the speed of string comparisons

String Interning in Python: A Hidden Gem That Makes Your Code Faster
String Interning in Python: A Hidden Gem That Makes Your Code Faster
Photo by wu yi on Unsplash

The string interning is a very helpful mechanism in Python to make string comparisons much faster. Unfortunately, how it works and how to use it properly are not very intuitive for beginners. If we don’t understand it, sometimes we could be confused about some unexpected results.

For example, the results of the following string comparisons may surprise you:

>>> a = "Yang"
>>> b = "Yang"
>>> a is b
True
>>> c = "Yang Zhou"
>>> d = "Yang Zhou"
>>> c is d
False

As we knew, the is operator is used to compare whether two variables refer…

Yang Zhou

Full Stack Hacker

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store