[Tutor] lists
Mark Lawrence
breamoreboy at gmail.com
Fri Nov 27 16:50:48 EST 2020
On 27/11/2020 21:09, nathan tech wrote:
Would you please not top post here as it's highly irritating.
> 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):
That'll fail as a list can't be passed to range, plus using range is
almost inevitably a code smell in python.
>
> 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
--
My fellow Pythonistas, ask not what our language can do for you, ask
what you can do for our language.
Mark Lawrence
More information about the Tutor
mailing list