Go back in the evening to review the original information, return to the codebook there is a "expand a nested Sequence" topic.
Task description: The child in the sequence may be a sequence, the child of the subsequence may still be a sequence, and so on, the sequence nesting can reach any depth. You need to loop through a sequence and expand all of its subsequence into a single sequence with only the basic subkeys.
For example, the shape is the following sequence a:
a = [(123 (7" , 45, 69, 10)]],
(Figure 1), and I might have a problem understanding the atomic level elements that are described in the task. My understanding is that I want to spit out this sequence.
such as the shape of[2, 3, (7, 8)] And< Span style= "color: #cc7832;" >< Span style= "color: #cc7832;" > (9 can still be split, the result of Figure 1 is only to the second layer when the sequence is not split, so do it yourself to do this implementation, so that the final result 2 is shown:
< Span style= "font-size:15px;" >< Span style= "color: #6897bb;" >< Span style= "color: #6897bb;" > (Figure 2).
< Span style= "font-size:15px;" >< Span style= "color: #6897bb;" >< Span style= "color: #6897bb;" >
< Span style= "font-size:15px;" >< Span style= "color: #6897bb;" >< Span style= "color: #6897bb;" >
< Span style= "font-size:15px;" >< Span style= "color: #6897bb;" >< Span style= "color: #6897bb;" >
def flatten (sequence): For i in sequence: if Isinstance (i, (list, tuple)): Flatten (i) if not isinstance (I, (list, tuple)): For subitem in I: print subitem else: print I
See this article by the way with their own ideas on the way to think about, feel that such treatment is still valuable, recorded. Convenient for later use ....
Python (sequence recursion) "Output atomic level element ... 】