Flashcards
Word pattern
Flashcards do conjunto (1)
- 1Input: pattern = "abba", str = "dog cat cat dog" Output: trueclass Solution:
def wordPattern(self, pattern: str, str: str) -> bool:
strSplit = str.split()
patSplit = [pattern[i:i+1] for i in range(0, len(pattern))]
if len(patSplit) != len(strSplit): return False
strDict = {}
for i,j in zip(strSplit,patSplit):
if i in strDict:
if strDict[i] != j:
return False
elif j in strDict.values():
return False
else:
strDict[i] = j
return True
Informações
- Descrição
- FlashCards sobre Word pattern, criado por Suhas S em 14-09-2019.
- Criado por
- Suhas S
- Visualizações
- 0
- Avaliação