我已经定义了一个函数
def pair(m,v):
ans = []
for x in m:
for sub in x[-1]:
if sub[1] == v:
ans = ans + [x[0][0], sub[0]]
print ans
然后我设置pairing = pair(regs,5)
我得到了所需的输出:
[['551c1', 5], ['2665d1', 11], ['2784a1', 5], ['3112b1', 5], ['3280i1', 7], ['3380d1',7], ['3474f1', 5], ['3774d1', 7], ['3782a1', 5], ['3879d1', 13], ['4086b1', 7], ['4556b1', 11], ['4600m1', 7], ['4617d1', 5], ['4656k1', 7], ['4979b1', 5], ['5094e1', 5], ['5982h1', 7], ['6501b1', 5], ['6786f1', 5], ['7232c1', 5], ['7566j1', 5], ['7617a1', 5], ['7742m1', 5], ['7826m1', 5], ['7974k1', 5], ['8262c1', 7], ['8528h1', 5], ['8534b1', 7], ['8710h1', 7], ['8949a1', 5], ['9048n1', 5], ['9285e1', 7], ['9520l1', 11], ['9559d1', 7], ['9622d1', 7], ['9650f1', 7], ['9865b1', 13], ['10082c1', 7], ['10549c1', 13], ['10789a1', 5], ['10926a1', 5], ['10994d1', 5], ['11482a1', 5], ['11610e1', 13], ['11840g1', 13], ['11907z1', 5], ['12114b1', 5], ['13002b1', 5], ['13188b1', 5], ['13328x1', 5], ['13502d1', 5], ['13630j1', 7], ['14123c1', 7], ['14577b1', 7], ['14706b1', 5], ['15246h1', 13], ['15575e1', 13], ['15834b1', 5], ['16224n1', 17], ['16491e1', 7], ['16577g1', 5], ['16880r1', 7], ['16936a1', 5], ['17157c1', 5], ['17507k1', 5], ['17584c1', 5], ['17898b1', 5], ['19043a1', 11], ['19431a1', 5], ['19620m1', 7]]
为什么当我现在进行len(配对)时,我收到以下错误:
TypeError: object of type 'NoneType' has no len()
答案 0 :(得分:1)
因为你不是return
来自你的功能。
尝试更改
print ans
到
return ans
或者,如果您想保留print
语句,请将return ans
放在其下方。