1 Star 0 Fork 0

mamh-mixed/python-cookbook

加入 Gitee
与超过 1400万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
recursiveStrings.py 968 Bytes
一键复制 编辑 原始数据 按行查看 历史
Ataba 提交于 2022-05-20 20:18 +08:00 . recursive string checker
""" author: Ataba29
code has a matrix each list inside of the matrix has two strings
the code determines if the two strings are similar or different
from each other recursively
"""
def CheckTwoStrings(str1, str2):
# function takes two strings and check if they are similar
# returns True if they are identical and False if they are different
if(len(str1) != len(str2)):
return False
if(len(str1) == 1 and len(str2) == 1):
return str1[0] == str2[0]
return (str1[0] == str2[0]) and CheckTwoStrings(str1[1:], str2[1:])
def main():
matrix = [["hello", "wow"], ["ABSD", "ABCD"],
["List", "List"], ["abcspq", "zbcspq"],
["1263", "1236"], ["lamar", "lamars"],
["amczs", "amczs"], ["yeet", "sheesh"], ]
for i in matrix:
if CheckTwoStrings(i[0], i[1]):
print(f"{i[0]},{i[1]} are similar")
else:
print(f"{i[0]},{i[1]} are different")
main()
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/mamh-mixed/python-cookbook.git
git@gitee.com:mamh-mixed/python-cookbook.git
mamh-mixed
python-cookbook
python-cookbook
master

搜索帮助