| def is_sorted(lst): | |
| ''' | |
| Given a list of numbers, return whether or not they are sorted | |
| in ascending order. If list has more than 1 duplicate of the same | |
| number, return False. Assume no negative numbers and only integers. | |
| Examples | |
| is_sorted([5]) β True | |
| is_sorted([1, 2, 3, 4, 5]) β True | |
| is_sorted([1, 3, 2, 4, 5]) β False | |
| is_sorted([1, 2, 3, 4, 5, 6]) β True | |
| is_sorted([1, 2, 3, 4, 5, 6, 7]) β True | |
| is_sorted([1, 3, 2, 4, 5, 6, 7]) β False | |
| is_sorted([1, 2, 2, 3, 3, 4]) β True | |
| is_sorted([1, 2, 2, 2, 3, 4]) β False | |
| ''' | |
| count_digit = dict([(i, 0) for i in lst]) | |
| for i in lst: | |
| count_digit[i]+=1 | |
| if any(count_digit[i] > 2 for i in lst): | |
| return False | |
| if all(lst[i-1] <= lst[i] for i in range(1, len(lst))): | |
| return True | |
| else: | |
| return False | |