Created
November 8, 2016 18:29
-
-
Save ViktorovEugene/51a60ac0b71e382496a8ed41e1f13b72 to your computer and use it in GitHub Desktop.
Utility function that accepts list with nested structure and returns flat list.
This file contains hidden or 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 flatten_list(list_to_flatten): | |
flat_list = [] | |
for item in list_to_flatten: | |
if type(item) != list: | |
flat_list.append(item) | |
else: | |
flat_list += flatten_list(item) | |
return flat_list |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment