def is_match(word, match):
# Test if all the characters in word are also in match.
return all(c in match for c in word)
def has_any_match(main, match):
# Test if there is any word in main that matches.
return any(is_match(word, match) for word in main)
首先,您必须将输入的数字转换成字符串,因为您对它们包含的数字感兴趣,而不是实际值。您可以使用
str
来执行此操作。在为了解决实际问题,您需要检查main中是否存在任何字符串,以便该字符串中的所有字符都包含在字符串匹配中。在
下面是一个更完整的测试程序:
^{pr2}$输出:
如果一行代码太多而无法吸收,您可能需要将其拆分:
以下是@unutbu's answer的变体:
其中
map = itertools.imap
也许使用
sets
检查一个集合是否是另一个集合的子集:相关问题 更多 >
编程相关推荐