def test_hashtable_collision():
    hashtable = Hashtable()
    hashtable.add("key", "value1")
    hashtable.add("yek", "value2")
    assert hashtable._hash("key") == hashtable._hash("yek")
    assert hashtable.get("key") == "value1"
    assert hashtable.get("yek") == "value2"
def test_left_join():
    h1 = Hashtable()
    h1.add("2", 2)
    h1.add("3", 3)

    h2 = Hashtable()
    h2.add("2", 2)
    h2.add("4", 4)

    assert left_join(h1, h2) == [['3', 3, None], ['2', 2, 2]]
Пример #3
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 ""
def ht_right():
    ht = Hashtable()
    ht.add("fond", "averse")
    ht.add("wrath", "delight")
    ht.add("diligent", "idle")
    ht.add("guide", "follow")
    ht.add("flow", "jam")
    return ht
def ht_left():
    ht = Hashtable()
    ht.add("fond", "enamored")
    ht.add("wrath", "anger")
    ht.add("diligent", "employed")
    ht.add("outfit", "garb")
    ht.add("guide", "usher")
    return ht
Пример #6
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 test_hashtable_add_and_get():
    hashtable = Hashtable()
    hashtable.add("key", "value")
    assert hashtable.get("key") == "value"
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)]