You are viewing a single comment's thread. Return to all comments →
a = int(input())
b = (raw_input().split(" "))
b.sort() #-----> sort is not working for negative numbers here only any idea ??
for i in range(len(b)):
if b[i] < b:
I always use my costum sort, you can try it. Also, a while seems better than a if+break. ...And you can do reversed(xrange(len(b)).
if len(A)<=1: return A
return qsort([x for x in A if x<A])+[x for x in A if x==A]+qsort([x for x in A if x>A])
Can you pls explain how this works??
Its working for negative numbers.check this
First, convert the elements b to integers . Your sorting should work then. Right now , it is sorting on strings not on integers.
sort wont work because you are taking a string. try to use map and map int function on your list.
@purushoth it is because you have not converted your list of strings to int
b = map(int,raw_input().split())
also note that .split() defaults to splitting on spaces e.g. " "