python - “TypeError:'NoneType'对象不可迭代”在python
问题描述
我的代码:我从网站上获取并编辑了一些以获取列表作为输出
def anit_printArr(a, n):
b=[]
for i in range(n):
b.append(a[i])
#yield b #I tried this, but then it shows error: TypeError: 'NoneType' object is not iterable
print(b)
# Generating permutation using Heap Algorithm
def anit_heapPermutation(a, size, n):
# if size becomes 1 then prints the obtained
# permutation
if (size == 1):
anit_printArr(a, n)
return
for i in range(size):
anit_heapPermutation(a,size-1,n);
# if size is odd, swap first and last
# element
# else If size is even, swap ith and last element
if size&1:
a[0], a[size-1] = a[size-1],a[0]
else:
a[i], a[size-1] = a[size-1],a[i]
# Driver code
a = [1, 2, 3, 4]
n = len(a)
anit_heapPermutation(a, n, 3) #This works fine, I tried to yield but...
for i in anit_heapPermutation(a, n, 3): #I want to use like this
print(i) #This gives: TypeError: 'NoneType' object is not iterable
我想在 for 循环中迭代这个函数,但出现错误。是的,我是初学者。
解决方案
推荐阅读
- android - Gradle 错误错误:清单合并失败:
- playframework - 是否可以在 Play Framework 2.7 中访问动作组合中的路由参数?
- influxdb - 我可以从 .log 文件向 influxdb 插入数据吗
- asp.net-mvc - .net core 2.2 使用 taghelpers 调用操作并传递查询字符串
- java - Hibernate:找不到命名参数
- symfony - 查询生成器“addSelect”影响“addOrderBy”
- php - 如何在 CodeIgniter 中调整图像大小?
- c - 我的 13 阶乘输出不正确,我该如何解决?
- android - Retrofit2如何使用内联标签解析xml
- jenkins - 无法在 Jenkins 作业中标记 SVN