How do I check for unsorted string within the list? If it is unsorted the function called need to return true
list([['3C', 'AS', '2H']])
list([['0C', 'JH', 'QS', 'KH', '9D']])
How do I check for unsorted string within the list? If it is unsorted the function called need to return true
list([['3C', 'AS', '2H']])
list([['0C', 'JH', 'QS', 'KH', '9D']])
You mean like this?
a = ['3C', 'AS', '2H']
b = ['0C', 'JH', 'QS', 'KH', '9D']
def sorted_or_not(lis):
if lis != sorted(lis):
return True
else:
return False
print(sorted_or_not(a))
print(sorted_or_not(b))
Output:
True
True
You might want to consider rephrasing your question. I'm not sure what you mean But one guess I have is that you want to check to see if a list has been sorted using the sorted() method:
ls = ['3C', 'AS', '2H']
ls2 = ['A', 'B', 'C']
def is_sorted(listr):
if listr == sorted(listr):
return True
else:
return False
print(is_sorted(ls))
print(is_sorted(ls2))
Basically the same as the other answer (but they beat me to it!)