输入:我有这个多个数组:
arr = [array(['ABU', 'KASS', '10KG'],dtype=object),array(['AL', 'YOUM14', 'HADCO'],dtype=object)]
代码1 :要在arr中循环遍历
for item in arr:
print(item)
输出代码1 :
['ABU', 'KASS', '10KG']
['AL', 'YOUM14', 'HADCO']
代码2 :检查数组中的项目是否包含数字
import numpy as np
arr1=['ABU', 'KASS', '10KG']
for a in arr1:
sum = 0
for i in range(10):
sum += a.count(str(i))
print(sum)
输入代码2 :
0
0
2
问题:如何使用code2循环遍历code1中的输出以获得以下输出:
['ABU', 'KASS', '10KG'] -> 0 0 2
['AL', 'YOUM14', 'HADCO'] -> 0 2 0
谢谢!
答案 0 :(得分:0)
希望这可能会有所帮助:)
import numpy as np
arr = [np.array(['ABU', 'KASS', '10KG'],dtype=object),np.array(['AL', 'YOUM14', 'HADCO'],dtype=object)]
arr1=['ABU', 'KASS', '10KG']
for arr1 in arr:
sum_list = []
for a in arr1:
sum = 0
for i in range(10):
sum += a.count(str(i))
sum_list.append(sum)
print(arr1,"->",sum_list)
答案 1 :(得分:0)
...您要发布编程作业吗?
for a in arr:
for b in a:
sum = 0
for i in range(10):
sum += b.count(str(i))
print(sum)