admin管理员组

文章数量:1122832

Just had a course where my teacher used this code, so i copied it to try it on pycharmcommunity and its says unresolved reference for helper_predicates, is_sorted, all_lte_all and is_permutation. When he used this code in class it worked perfectly, can someone explain if helper_predicates exists as a built in module or if I have to install something?

from helper_predicates import *
import random


def lusinvariant(values, orig_values, i):
    return is_sorted(values[:i]) and \
            is_permutation(values, orig_values) and \
            all_lte_all(values[:i], values[i:])

def minimum_position(values, start):
    minPos = start
    i = start + 1

    assert lte_all(values[minPos], values[start:i])
    while i != len(values):
        assert lte_all(values[minPos], values[start:i])

        if values[i] < values[minPos]:
            minPos = i

        i += 1
        assert lte_all(values[minPos], values[start:i])
    assert lte_all(values[minPos], values[start:i])
    return minPos


# Hint: def selection_sort_recursive(values, start)
def selection_sort(values):
    orig_values = values[:] # enkel nodig voor lusinvariant
    i = 0

    assert lusinvariant(values, orig_values, i)
    while i != len(values):
        assert lusinvariant(values, orig_values, i)

        minPos = minimum_position(values, i)
        values[i], values[minPos] = values[minPos], values[i]

        i += 1
        assert lusinvariant(values, orig_values, i)

    assert lusinvariant(values, orig_values, i)

# Test
lst = list(range(20))
random.shuffle(lst)
print(lst)

print("Iteratief:")
# Hint: selection_sort_recursive(kopie, 0)
selection_sort(lst)
print(lst)

本文标签: pycharmhelperpredicates module on python not foundStack Overflow