Skip to content

Instantly share code, notes, and snippets.

@chroming
Created January 10, 2017 05:13
Show Gist options
  • Save chroming/0fa75ed980554a346d9c7b73293bb7d5 to your computer and use it in GitHub Desktop.
Save chroming/0fa75ed980554a346d9c7b73293bb7d5 to your computer and use it in GitHub Desktop.
Python多层List转单层
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