Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我想计算双精度数组中非整数的数量。例如
Input: mylist=[['a',-2,'b',-3,1],['c','a',-1,1,3],['d','f'],['e',3],[-11]] Output: num_value(mylist)=7
告诉我怎么做。
计算列表列表中非整数的实例(for在生成器理解中使用 double 馈送到sum)
for
sum
mylist=[['a',-2,'b',-3,1],['c','a',-1,1,3],['d','f'],['e',3],[-11]] print(sum(1 for sl in mylist for x in sl if not isinstance(x,int)))
产量:7
7