我有一个列表,我想比较用户输入与该列表,但字符字符。例如,用户只能输入一些字符,其余的字符用点隔开。(例如:V…r..n) 如何逐字符比较字符串,如果它只包含用户输入的所有字符(跳过点)
list1 = ["Vaporeon", "Jolteon", "Flareon", "Espeon", "Umbreon", "Leafeon", "Glaceon", "Sylveon"]
s = input() # for example "V...r..n"
for i in list1:
# if s include exactly characters in i (skip the dots)
print(i)
可以使用正则表达式:
编辑:其他答案中似乎缺少的另一个选项是使用
itertools.zip_longest
:有几种方法可以解决它,用regex,用jpp的解决方案,或者用这个:
这里有一条路。有两个步骤。首先将索引映射到相关字符。然后检查这些索引是否相等。你知道吗
相关问题 更多 >
编程相关推荐