获取字符串中全部的回文子串
获取字符串中全部的回文子串
代码:
def get_all_Palindrome(item:str): ''' 获取所有的回文字符串 ''' #定义列表,存放所有的回文字符串 res = [] for i in range(len(item)): for j in range(i + 1, len(item) + 1): if item[i:j] == item[i:j][::-1]: res.append(item[i:j]) if res != '': return res
测试:
test = "cdabbacc" print(get_all_Palindrome(test))
结果:
['c', 'd', 'a', 'abba', 'b', 'bb', 'b', 'a', 'c', 'cc', 'c']
    知道、想到、做到、得到
 
                    
                     
                    
                 
                    
                
 
                
            
         
         浙公网安备 33010602011771号
浙公网安备 33010602011771号