"""utils.py
A utility module"""

# Imports
import random as rand
import numpy as np


# Functions
def loop(seq, i):
    """Used with a for loop to loop through the items on seq"""
    return seq[i % len(seq)]


def shuffle(seq):
    return rand.sample(seq, k=len(seq))


def print_grid(col, row, items):
    array = np.array(items)
    grid = np.reshape(array, (row, col))
    for column in grid:
        for item in column:
            print(item, end=" ")
        print()
    print()


def check_if_type(val, class_type, name="type"):
    "Check if isinstance(val, class_type) else raise Exception"
    if not isinstance(val, class_type):
        raise TypeError(f"Invalid {name}")
