有两个输入,第一个输入代表第二个输入的索引。我需要找到第二个输入的“X”位置是否相同?
输入:
123X56XX
Ahjutruu
Output:
True
例子: X in input one at 4,7,8
在第二个输入中 4、7、8 的位置是 'u' 都是相同的所以我需要打印“true”
我尝试使用枚举函数但没有成功:
a="123X56XX"
b="Ahjutruu"
xi=[]
for i,val in enumerate(a):
if val=='X':
xi.append(i)
print(xi)
#next step only i dont know how to doo please help
接下来不知道怎么查
最佳答案
将xi
的给定索引的所有值放入set
中,这个set的长度必须等于1:
xi = [i for i, c in enumerate(a) if c == 'X']
len(set([b[i] for i in xi])) == 1
https://stackoverflow.com/questions/71089606/