1
votes
a = []
for i in range (100,200):
    if i % 12==0:
        a.append(i)
print(a[-1])

I get output as 192. But without index calling if I use sort function like

a = [] 
for i in range (100,200):
    if i % 12==0:
        a.append(i)
print(a.sort(reverse=True))

I get output as none. Just want to know why sort is not working ?

2
I edited your answers and as part of that I added indent as I think it makes sense. However as indent changes meaning in python please check I did not change the meaningIvaylo Strandjev

2 Answers

0
votes

sort does not return the sorted list. Try like this:

a = []  
for i in range (100,200): 
    if i % 12==0: 
       a.append(i) 
a.sort(reverse=True)
print(a)
0
votes

In case you want the sorted list to be returned, you could use

print(sorted(a, reverse=True))