-6

Possible Duplicate:
How do I sort a list of strings in Python?

I wrote a program, whose output is a list, the problem is that I can't make the program to get the list in ascending order, so now I want to find a method to sort a list in ascending order, for any lenght , may you help me? These is my code:

import math
n=int(input())
notPrimes=[]
primes=[]
numbers=list(range(0,n))
numbers.remove(1)
numbers.remove(0)
for i in range(2,int(math.sqrt(n)+1)):
   for j in numbers:
    if j%i==0:
        notPrimes.append(j)
    if j in numbers:
        numbers.remove(j)
#notPrimes is the list I have to sort

These is my code, and I need that list in ascending order.

Community
  • 1
  • 1
Reginald
  • 429
  • 7
  • 9
  • 16

1 Answers1

3
numbers = sorted(numbers)

If you want descending order:

numbers = sorted(numbers, reverse=True)
omz
  • 53,243
  • 5
  • 129
  • 141