天天看點

Python學習筆記|字元串與正規表達式練習下

1.判斷變位詞,如果一個字元串是 另一個字元串的重新排列組合,那麼這兩個字元串互為變位詞。比如,”heart”與”earth”互為變位 詞,”Mary”與”arMy”也互為變位詞

x1=input()
x2=input()
if sorted(x1)==sorted(x2):
    print("yes")
else:
    print("no")
           

2.判斷回文串

x=input()
x=int(x)
for i in range(x):
    x1=input()
    x2=x1[::-1]
    if(x1==x2):
        print("Yes")
    else:
        print("No")
           
x=input()
count1=0
count2=0
count3=0
other=0
for i in x:
    if i.isalpha():
                count1+=1
    elif i.isspace():
                count2+=1
    elif i.isdigit():
                count3+=1
    else:
                other+=1
print(("%d %d %d %d")%(count1,count2,count3,other))

           
s=input()
k=int(input())
for p in s:
    if ord("a")<=ord(p)<=ord("z"):
        print(chr(ord("a")+(ord(p)-ord("a")+k)%26),end='')
    elif ord("A")<=ord(p)<=ord("Z"):
        print(chr(ord("A")+(ord(p)-ord("A")+k)%26),end='')
    elif u'\u4e00'<=s<=u'\u9fa5':
        print(chr(ord(p)+k),end='')
    else:
         print(p,end = '')

           
x=input()
str=str(x)
if str[0]=='-':
    str1=-int(str[:0:-1])
else:
    str1=int(str[::-1])
print(str1)