python 中 insert 返回 None


题目:"abcd" 和 "acdb" 称为转换字符串,请编写一个函数,判断输入的两个字符串是不是转换字符串。

本题有两个坑:1:insert 在使用的时候返回的字符串为None。2 :insert 在使用的时候数据已经插入原列表

s1 = "abcd"
s2 = "acdb"

def changeChar(s1, s2):
    lst_s1 = list(s1)
    lst_s2 = list(s2)
    lst_s2.insert(1, lst_s2.pop(-1))
    return True if lst_s1 == lst_s2 else False
      

if __name__ == "__main__":
    c = changeChar(s1, s2)
    print(c)

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM