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. …
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:
How can implement a stacking effect for them like the following?
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
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.
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…
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 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…
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. …
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…
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
band a string
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…
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
As we knew, the
is operator is used to compare whether two variables refer…
Full Stack Hacker