Open liangxinxin5102 opened 5 years ago
def flatten(nasted): try: for sublist in nasted: for element in flatten(sublist): yield element except TypeError: yield nasted
用递归来生成任意层的数据
def flatten(nasted): try: for sublist in nasted: for element in flatten(sublist): yield element except TypeError: yield nasted
生成器就是将一个列表里面含有列表生成一个列表,里面含有yield语句的函数