Assert type arguments in Python

PHOTO EMBED

Sun Mar 28 2021 07:00:39 GMT+0000 (Coordinated Universal Time)

Saved by @FlorianC #python

my_new_list = [6, 3, 8, "12", 42]

def OrganizeList(myList):
    for item in myList:
        assert type(item) == str, "Word list must be a list of strings"
    myList.sort()
    return myList

print(OrganizeList(my_new_list))
content_copyCOPY

assert can be used to preempt errors by checking if a given condition is met.