Write
```python
word_pattern(pattern, string)
```
that given a ```pattern``` and a string ```str```, find if ```str``` follows the same sequence as ```pattern```. 

For example:
```python
word_pattern('abab', 'truck car truck car') == True
word_pattern('aaaa', 'dog dog dog dog') == True
word_pattern('abab', 'apple banana banana apple') == False
word_pattern('aaaa', 'cat cat dog cat') == False
```

Difficulty: introductory

Starter code:

def word_pattern(pattern, string):
	

Solutions:
def word_pattern(pattern, string):
    x = list(pattern)
    y = string.split(" ")
    return (len(x) == len(y) and 
        len(set(x)) == len(set(y)) == len(set(zip(x, y)))
    )

def word_pattern(pattern, string):
    return [pattern.index(any) for any in pattern] == [string.split().index(any) for any in string.split()]

def word_pattern(pattern, string):
    match = {}
    
    if len(pattern) != len(string.split()): return False
    
    for c, word in zip(pattern, string.split()):
        # For a new character in pattern
        if c not in match: 
            # If word has already been assigned to a character, return false
            if word in list(match.values()): return False
            
            # else assign the word to the character
            match[c] = word
        
        # Match the word with the one assigned to the character
        if match[c] != word: return False
    
    return True


def word_pattern(pattern, string):
    
    words = string.split(' ')
    
    if len(words) != len(pattern):
        return False
    
    map, used = {}, set()
    
    for i, p in enumerate(pattern):
        
        w = words[i]

        if p not in map and w not in used:
            map[p] = w
            used.add(w)
        
        if map.get(p, None) != w:
            return False

    return True

def word_pattern(pattern, s):
  s = s.split()
  return len(set(zip(pattern, s))) == len(set(pattern)) == len(set(s)) and len(s) == len(pattern)

def word_pattern(pattern,string):
    print((pattern,string))
    string = string.split(' ')
    m = len(string); x = {}
    if m!=len(pattern) or len(set(pattern))!=len(set(string)):
        return False
    for k, s in zip(pattern,string):
        if k in x and s!=x[k]: return False
        x[k] = s
    return True


def word_pattern(pattern, string):
    words = string.split(" ")
    return len(pattern) == len(words) and len(set(zip(pattern, words))) == len(set(pattern)) == len(set(words))

def word_pattern(p, s):
    if len(p) != len(s.split()): return False
    ss = set([(p[i], c) for i, c in enumerate(s.split())])
    return len(ss) == len(set(p)) == len(set(s.split()))


from collections import OrderedDict


def get_pattern(iterable):
    unique_ordered = list(OrderedDict.fromkeys(iterable))
    return tuple(unique_ordered.index(a) for a in iterable)


def word_pattern(pattern, string):
    return get_pattern(pattern) == get_pattern(string.split())