The following small series will provide you with a comprehensive analysis of the Python-nested list. I think this is quite good. now I will share it with you and give you a reference. Let's take a look at a 3-layer nested list m.
M = ["a", ["B", "c", ["inner"]
Basic data items a, B, c, and inner must be parsed.
Basic data extraction methods:
For I in m:
Print I this can only retrieve the first layer of a, and a second layer of nested list ["B", "c", ["inner"]
Combined with built-in functions and judgment, you can continue to parse this list of 2 layers.
For I in m: if isinstance (I, list): for j in I: print jelse: print I result abc ['inner ']
This layer-2 nesting is also separated, but the list in it is not split. Although the splitting can continue to obtain the result, it is not the best choice.
Constructor, iteratively parse this multi-layer nested list
Def printm (listin): for I in listin: if isinstance (I, list): printm (I) else: print I use this function to directly parse the nested list, remove printm (m) at a time)
The result is as follows:
Abcinner
The full analysis of the above Python-nested list is all the content shared by the editor. I hope to give you a reference and support for PHP.
For more articles about parsing the Python-nested list, refer to the Chinese PHP website!