判断是否互为字符串重排
作者:互联网
输入两个字符串,分别为s1和s2,将其中一个重新排序后是否与另一个字符串相等
num = 0
x = 0
s1 = input('请输入字符串1:')
s2 = input('请输入字符串2:')
st1 = list(s1)
st2 = list(s2)
while True:
if st1 == []:
break
if x == len(st2):
num = 1
break
elif st1[0] == st2[x]:
st1.pop(0)
st2.pop(x)
x = 0
else:
x += 1
print(num == 0 and len(s1) == len(s2))
标签:s2,s1,互为,num,st1,st2,重排,字符串 来源: https://www.cnblogs.com/golden-tea/p/15729994.html