lst =['风清扬','东方不败','依林','田伯光']deffun(lst):
new_list=[]for i in lst:iflen(i)>3:
new_list.append(i)print(new_list)
fun(lst)
list1=[i for i in lst iflen(i)>3]# 列表推导式使用的代码量更少print(list1)
# 创建生成器的方法# 方法一:使用类似列表推导式的方式得到生成器
g =(x *3for x inrange(10))print(next(g))print(next(g))# 方法二:使用函数加上yield来实现生成器deffun():
i=0whileTrue:
i+=1yield i
r=fun()print(r)print(next(r))print(next(r))