Python 對字串進行切割

求該題目程式碼

(1)首先,輸入一串不超過50字元的字串(不得有空格)及一正整數K,兩者以一個空格為間隔
(2)去除字串間非英文字母的字元,例如the$sky@iS!soBlue 應轉換成theskyiSsoBlue
(3)再對字串做大小寫的互相轉換,例如theskyiSsoBlue 應轉換成 THESKYIsSObLUE
(4)對字串以每隔K個字元進行切割,最後一組若字元數不足K則無視
例如:當K=3時,THESKYIsSObLUE 應切割成THE、SKY、IsS、ObL、UE共計5組字串
(5)將每組切割好的字串進行順序反轉後,並以【/】作為間隔輸出。
例如:THE、SKY、IsS、ObL、UE應轉換並輸出UE/ObL/IsS/SKY/THE
==============
Sample input 1:
abcda 1

Sample output 1:
A/D/C/B/A
==============
Sample input 2:
abcDefgHiaaA 2

Sample output 2:
Aa/IA/Gh/EF/Cd/AB
==============
Sample input 3:
mynameisBig5666hehe 10

Sample output 3:
GHEHE/MYNAMEISbI
==============
Sample input 4:
iHaveAnApple 15

Sample output 4:
IhAVEaNaPPLE
==============
Sample input 5:
@H#hHhhhh12*4%H287 3

Sample output 5:
Hh/HHH/hHh



def analyse():
    data = input()
    datalist = data.split(' ')

    res = ''
    for i in datalist[0]:
        if (i>='a' and i<='z'):
            res += i.upper()
        elif  (i>='A' and i<='Z'):
            res += i.lower()
        else:
            pass

    # 分割
    res2 = []
    idnex = int(datalist[1])
    tmp = ''
    c = 0
    for i in res:
        if c % idnex == 0 and not c == 0:
            res2.append(tmp)
            tmp = i
        else:
            tmp += i
        c += 1
    res2.append(tmp)

    #
    res3 = res2.reverse()
    data3 = '/'.join(res2)
    print(data3)

analyse()

s,K = input(">>>").split()
K = int(K)


s2 = ''.join([i for i in s if 'z' >= i.lower() >= 'a'])
s3 = s2.swapcase()

i = 0
res = []
while i + K <= len(s3):
    res.append(s3[i:i + K])
    i += K
if i < len(s3):
    res.append(s3[i:])

resReverse = res[::-1]
print('/'.join(resReverse))
'''
--result
>>>abcDefgHiaaA 2
['AB', 'Cd', 'EF', 'Gh', 'IA', 'Aa']
Aa/IA/Gh/EF/Cd/AB

'''

s0,l = input("请输入:").split(" ")
l = int(l)

s1 = "".join([i for i in s0 if i.lower() >= 'a' and i.lower() <= 'z'])

s2 = s1.swapcase()

res = []
while len(s2) >= l:
    tmp = s2[0:l]
    res.append(tmp)
    s2 = s2[l:]
res.append(s2)

resList = res[::-1]

print("/".join(resList))