Hi, I’m Pippy.
One, foreword
A few days ago, a fan of the Python Bronze exchange group called “Hunting Shadow” asked a question about time switching.
Topic: two lists: [1, a, ‘ ‘, c, ‘ ‘, ‘ ‘, f] and [2, ‘ ‘b,’ ‘, d, e, ‘], how to merge into a new list: [3, a, b, c, d, e, f] among them a, b, c, d, e, f are strings.
Second, the solution process
This problem looks very confusing, directly add up, will report an error, string and number add incompatible, need to do some simple processing, this topic is very interesting, consolidate the foundation pretty good, here give [(this is the back of the moon)] big guy answer, together look at it.
Method 1: routine treatment
And just to make a judgment, based on the fact that both 1 and 2 in this list are STR,
After you run it, you get the answer.
Without that judgment, the answer would look something like this:
If both 1 and 2 in the list are int types, a simple list derivation can do the trick, as shown in the following figure:
Method 2: list derivation
It may seem a little confusing to use list derivation in one step, but it’s a good way to do it.
In this way, it can also meet the requirements of fans.
conclusion
Hello, I’m Pipi. This article, based on fans’ questions, provides a solution to the problem of list data combination, which is effective and helps fans to solve the problem smoothly.
Finally, I would like to thank my fans [Hunting film] for their questions, and [(this is the back of the moon)] for their support of ideas and code.
Finally, we arranged a big man to share a regular expression knowledge, feeling pretty good, full of dry goods! The function is to extract the English characters in the garbled string.
Welcome to actively try, there are good content can also share with me oh!
Friends, quickly use the practice! If you have any problems during the learning process, please add me as a friend and I will invite you to join the Python Learning exchange group to discuss and learn together.