Exemplo n.º 1
0
def tree_intersection(tree_1, tree_2=0):
    arr = []
    hashtable = Hashtable()
    top = tree_1.preOrder().top
    while top:
        if not hashtable.contains(top.value):
            hashtable.add(0, top.value)
        top = top.next
    top = tree_2.preOrder().top
    while top:
        if hashtable.contains(top.value):
            arr.append(int(top.value))
        top = top.next
    return arr
Exemplo n.º 2
0
def test_hashtable_contains_true():
    hashtable = Hashtable()
    hashtable.set('listen',1)

    actual = hashtable.contains('listen')
    expected = True

    assert actual == expected
Exemplo n.º 3
0
 def twoSumWithHash(self, nums, target):
     hashtable = Hashtable()
     for i in range(len(nums)):
         # Check if complement exists.
         if hashtable.contains(target - nums[i]):
             # Return it if it does.
             return [hashtable.get(target - nums[i]), i]
         else:
             hashtable.put(nums[i], i)
Exemplo n.º 4
0
def repeated_word(sentence):
    words = sentence.split()
    for w in range(len(words)):
        pattern = r'[^\w\s]'
        words[w] = re.sub(pattern,'', words[w])
    hash = Hashtable()
    for word in words :
        if hash.contains(word.upper()):
            return word
        hash.add(word,word.upper())
Exemplo n.º 5
0
def repeated_word_check(text_to_check):
    case_format = text_to_check.lower()
    punctuation_clean = case_format.translate(
        str.maketrans('', '', string.punctuation))
    iterable_words = punctuation_clean.split()
    ht = Hashtable()

    for word in iterable_words:
        if ht.contains(word):
            return word
        else:
            ht.set(word, word)
    return 'No Words Repeated'
Exemplo n.º 6
0
def test_does_not_contain():
    new_hashtable = Hashtable()
    assert new_hashtable.contains('Couch') == False
Exemplo n.º 7
0
def test_contains():
    new_hashtable = Hashtable()
    new_hashtable.add('Soda', 'MtnDew')
    assert new_hashtable.contains('Soda') == True
Exemplo n.º 8
0
def test_contains_false():
    hashtable = Hashtable()
    hashtable.add('roger', 45)
    actual = hashtable.contains('roger')
    expected = False
    assert actual == expected
Exemplo n.º 9
0
def test_contains_false():
    ht = Hashtable()
    ht.add('potato', 'object')
    assert ht.contains('test') is False
Exemplo n.º 10
0
def test_contains_true():
    ht = Hashtable()
    ht.add('test', 'object')
    assert ht.contains('test') is True