A function in Python that sorts a list

 


def sortlist(listname, string):
    if string == "asc":
        return sorted(listname)
    elif string == "desc":
        return sorted(listname, reverse=True)
    elif string == "none":
        return listname
    else:
        print("Wrong Input!")
       
list1 = [4,8,6,1,9,56,33,19,2,55,14]
list2 = ["z","v","c","r","h","a","s","m","f"]

print(sortlist(list2, "none"))




Comments

Popular posts from this blog

Quotation marks to wrap an element in HTML

What is the difference between iostream and iostream.h in cpp?

The Basic Structure of a Full-Stack Web App