Comparing digits in an integer in Python

后端 未结 3 1008
慢半拍i
慢半拍i 2021-01-16 12:48

Really need some help here. Super early in learning Python.

The goal is to take a number and see if the digits are in ascending order. What I have so far is:

3条回答
  •  情歌与酒
    2021-01-16 13:29

    If you're working with such a small number of digits, just create a new list w/ the elements in ascending order. Fortunately, Python has a function that does exactly that, the built-in function sorted:

    def is_ascending(lst):
        return sorted(lst) == lst
    

提交回复
热议问题