Answers for "bogo sort python"

0

bogo sort python

def is_sorted(data) -> bool:
    """Determine whether the data is sorted."""
    return all(data[i] <= data[i + 1] for i in range(len(data) - 1))

def bogo_sort(data) -> list:
    """Shuffle data until sorted."""
    count = 0
    while not is_sorted(data):
        shuffle(data)
        temp_str = " "
        count += 1
        for i in range(len(data)):

            temp_str = temp_str + " " + str(data[i])

        print(temp_str)
        print(count)
    return data
Posted by: Guest on May-01-2021

Python Answers by Framework

Browse Popular Code Answers by Language