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,520 points
12,793 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,910 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
746 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,090 points
22,692 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,300 points
586 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
891 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 7, 2019 in Python by Neha
• 330 points

edited Jul 8, 2019 by Kalgi 4,060 views
0 votes
1 answer
+5 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,790 points
3,479 views
0 votes
1 answer

How to check the value is double in the existing data that when ever the values are double print thats value

Hey, @There, I guess regarding your query you ...READ MORE

answered Nov 3, 2020 in Python by Gitika
• 65,910 points
675 views
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,910 points
775 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP