How to check if list is ascending

0 votes

How to check if the list is ascending?

Oct 12, 2020 in Python by anonymous
• 10,420 points
337 views

1 answer to this question.

0 votes

You can go through the example given: 

# using naive method to 

# check sorted list 

flag = 0

i = 1

while i < len(test_list):

    if(test_list[i] < test_list[i - 1]):

        flag = 1

    i += 1

     

# printing result

if (not flag) :

    print ("Yes, List is sorted.")

else :

    print ("No, List is not sorted.")

Output :

Original list : [1, 4, 5, 8, 10]
Yes, List is sorted.
answered Oct 12, 2020 by Gitika
• 65,870 points

Related Questions In Python

0 votes
1 answer

How to check if a list is empty in python?

To check if a list is empty ...READ MORE

answered May 27, 2019 in Python by Nisa
• 1,090 points
201 views
+1 vote
1 answer

How to check if a string is null in python

Try this: if cookie and not cookie.isspace(): # the ...READ MORE

answered Aug 20, 2018 in Python by Priyaj
• 58,100 points
18,035 views
0 votes
1 answer

How do I check if a list is empty?

You can try the following: if not a:   print("List ...READ MORE

answered Mar 14, 2019 in Python by SDeb
• 13,250 points
138 views
0 votes
1 answer

How to check if a substring is present in a string using Python?

To check if the substring exists in ...READ MORE

answered May 9, 2019 in Python by Sharan
286 views
0 votes
2 answers
+1 vote
2 answers

how can i count the items in a list?

Syntax :            list. count(value) Code: colors = ['red', 'green', ...READ MORE

answered Jul 6, 2019 in Python by Neha
• 330 points

edited Jul 8, 2019 by Kalgi 1,843 views
0 votes
0 answers
+4 votes
6 answers

Lowercase in Python

You can simply the built-in function in ...READ MORE

answered Apr 11, 2018 in Python by hemant
• 5,810 points
1,420 views
0 votes
1 answer
0 votes
1 answer

How to print error in web browser if there is error in code?

You can try to catch these errors ...READ MORE

answered Nov 6, 2020 in Python by Gitika
• 65,870 points
87 views