[Tutor] lists

nathan tech nathan-tech at hotmail.com
Fri Nov 27 16:09:34 EST 2020


Hello,


Would not this work?


if(l[0]>l[1]):

  print("all is well.")


Or if you wanted to look at the whole list something like:


def is_great(l):

  pos=0

  for x in range(l):

   if(x==len(l)):

    return True

  if(l[x]>l[x+1]):

    return False



May need some slight bug checks on that function as I threw it together 
off the top of my head but.

HTH

Nathan


On 27/11/2020 19:54, Bernardo Rebelo wrote:
> Hi I would like to know how to check if an element in a list is greater
> than the next element on the same list like this
>
> [5,4,3,2,1]
>
> if 5 > 4 > 3 > 2 > 1
> return True
>
> in an example like this one [5,4,5,2], it would give False.
>
> best regards,
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> To unsubscribe or change subscription options:
> https://nam11.safelinks.protection.outlook.com/?url=https%3A%2F%2Fmail.python.org%2Fmailman%2Flistinfo%2Ftutor&data=04%7C01%7C%7Cf39ed758a60349382e9408d893182d0b%7C84df9e7fe9f640afb435aaaaaaaaaaaa%7C1%7C0%7C637421079326204248%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C1000&sdata=f4mJyKL0z6kLn8NKbBJmZG3%2FTuDs%2FbnLYDfHnkEd3l4%3D&reserved=0


More information about the Tutor mailing list