Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PYTHON

word pattern in python

def wordPattern(pattern, s):
    dict1 = {}
    dict2 = {}

    for key,value in enumerate(list(s.split(" "))):
        if value not in dict1:
            dict1[value]= [key]
        else:
            dict1[value].append(key)

    for key,value in enumerate(pattern):
        if value not in dict2:
            dict2[value]= [key]
        else:
            dict2[value].append(key)

    return (list(dict1.values()) == list(dict2.values()))
Source by eolnuha.com #
 
PREVIOUS NEXT
Tagged: #word #pattern #python
ADD COMMENT
Topic
Name
2+2 =