GoConqr has a new look! Let us know what you think.

Flashcards

Word pattern

Suhas S English 1 card

Cards in this deck (1)

  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

Information

Description
Flashcards on Word pattern, created by Suhas S on 14/09/2019.
Created by
Suhas S
Views
0
Rating

Feedback

What is it about?

What do you think of the new look?

How do you like it?