-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.

0

1 Answer 1

3
numbers = sorted(numbers) 

If you want descending order:

numbers = sorted(numbers, reverse=True) 
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.