2015-03-29 4 views

ответ

1

Я обычно использую это recipe:

import collections 


def flatten(l): 

    for el in l: 
     if isinstance(el, collections.Iterable) and not isinstance(el, str): 
      for sub in flatten(el): 
       yield sub 
     else: 
      yield el 


print(list(flatten([[1],[[1,2],[3]]]))) 
# [1, 1, 2, 3] 
Смежные вопросы