Created
January 10, 2017 05:13
-
-
Save chroming/0fa75ed980554a346d9c7b73293bb7d5 to your computer and use it in GitHub Desktop.
Python多层List转单层
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def switch_re(the_list): | |
""" | |
多层list转单层 | |
:param the_list: 需要转换的List | |
:return: 单层List | |
""" | |
if isinstance(the_list, list): | |
now = the_list[:] | |
res = [] | |
while now: | |
head = now.pop(0) | |
if isinstance(head, list): | |
now = head+now | |
else: | |
res.append(head) | |
return res | |
else: | |
return the_list |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment