Example #1
0
def repeated_word(string):
    ht = Hashtable()
    valid = "abcdefghijklmnopqrstuvwxyz "
    words = "".join(ch for ch in string.lower() if ch in valid).split()

    for word in words:
        if ht.contains(word):
            return word
        ht.add(word, word)

    return ""
Example #2
0
def repeated_word(strs): 

  strs = strs.lower()

  for ch in strs: 
    if ch not in ABC_dict: 
      strs.replace(ch, '')

  str_lst = strs.split(" ")

  ht = Hashtable()

  for string in str_lst: 
    if ht.contains(string): 
      return string
    else: 
      ht.add(string, string)  

  return None    
def test_hashtable_contains():
    hashtable = Hashtable()
    hashtable.add("key", "value")
    assert hashtable.contains("key") == True  
def tree_intersection(bn1, bn2):
    ht = Hashtable()
    for n in bn1.pre_order():
        ht.add(n, n)
    return [n for n in bn2.pre_order() if ht.contains(n)]