liangxinxin5102 / PAT

Some PAT questions and ancesters
0 stars 0 forks source link

python 暑期学习之旅 #9

Open liangxinxin5102 opened 5 years ago

liangxinxin5102 commented 5 years ago

用递归来生成任意层的数据

def flatten(nasted): try: for sublist in nasted: for element in flatten(sublist): yield element except TypeError: yield nasted

生成器就是将一个列表里面含有列表生成一个列表,里面含有yield语句的函数