如果我有一个这样的数字数组,我需要它来打印“1”,因为它是比较每个字符串时最早的匹配字符
Numbers = ["590", "390", "160", "170", "170"]
运行我在下面编写的代码会得到数字“2”,因为它是第一个匹配字符。那是我能做的最远的事了,我不知道该怎么办了。你知道吗
import itertools
import math
qw = "5234"
qe = "4211"
match = list(set(qw.lower()) & set(qe.lower()))
minPoint = match.index(min(match))
match[minPoint]
你的
set
想法是正确的,但是你可能想先zip
,因为这将你想要比较的数字分组在一起。 最方便的方法是使用collections.Counter
类相关问题 更多 >
编程相关推荐