有大佬帮忙看一道题吗
Write a function called same_pattern that returns true or false depending on whether two stringshave the same pattern of characters. More precisely, two strings have the same pattern if they are ofthe same length and if two characters in the first string are equal, if and only if the characters in thecorresponding positions in the second string are also equal. Below are some examples of patterns thatare the same and patterns that differ (keep in mind that the method should return the same value nomatter what order the two strings are passed). 1st String 2nd String Same Pattern? --------------- -------------- ------------------"" "" True"a" "x" True
"a" "ab" False
"ab" "ab" True
"aa" "xy" False
"aba" "+-+" True
"---" "aba" False
"abcabc" "zodzod" True
"abcabd" "zodzoe" True
"abcabc" "xxxxxx" False
"aaassscccn" "aaabbbcccd"
True "asasasasas" "xyxyxyxyxy" True
"ascneencsa" "aeiouuoiea" True
"aaassscccn" "aaabbbcccd" True
Your function should take two parameters: the two strings to compare. You are allowed to createnew strings, but otherwise you are not allowed to construct extra data structures to solve this problem(no list, set, dictionary, etc). You are limited to the string functions on the cheat sheet.
因为直接打字太麻烦所以我写在了纸上
file:///C:/Users/DELL/Desktop/%E5%87%BD%E6%95%B0same_pattern.jpg
{:10_297:} 怎么发图片啊 https://s3.ax1x.com/2021/03/07/6KS5id.jpg 好吧一开始我以为是电脑存储地址。。。 def same_pattern(a,b):
la,lb = len(a),len(b)
if la == lb == 1:
return True
if la != lb:
return False
for i in range(la):
if not a.index(a) == b.index(b):
return False
break
else:
return True
页:
[1]