Tags
 IOS SQL HTML C RUBY-ON-RAILS MYSQL ASP.NET DEVELOPMENT RUBY .NET LINUX SQL-SERVER REGEX WINDOWS ALGORITHM ECLIPSE VISUAL-STUDIO STRING SVN PERFORMANCE APACHE-FLEX UNIT-TESTING SECURITY LINQ UNIX MATH EMAIL OOP LANGUAGE-AGNOSTIC VB6

# Python .sort() does not fully order numbers

By : Clayton Armstrong-19
Date : October 18 2020, 06:10 PM
I wish did fix the issue. You're sorting strings, not numbers, your getVolume needs to convert the values to float first:
code :
``````def getVolume(e):
return float(e["priceChangePercent"])
``````
``````tickers.sort(reverse = True, key = lambda x : float(getVolume(x)))
``````

Share :

## What is the standard sort order for Python release/version numbers?

By : paulo tipay
Date : March 29 2020, 07:55 AM
should help you out This is a sore point for many folks. setuptools and easy_install have some rather bizarre rules in an attempt to play nice with everybody. You can read the full rules in setuptools's parse_version method, but here's the summary:

## Sort all even numbers in ascending order and then sort all odd numbers in descending order in a collection

By : Lubomir
Date : March 29 2020, 07:55 AM
To fix the issue you can do Any collection that supports sorting with a custom comparer will do - even an array. Implement your custom comparator as follows:
code :
``````public int compare(int x, int y) {
if (x&1 == y&1) {
// Both numbers are odd or both numbers are even
if (x&1 == 0) {
// Both numbers are even: compare as usual
return Integer.compare(x, y);
} else {
// Both numbers are odd: compare in reverse
return Integer.compare(y, x);
}
}
// One is odd, the other one is even
if (x&1 == 0) {
return -1;
}
return 1;
}
``````

## python: order a list of numbers without built-in sort, min, max function

Date : March 29 2020, 07:55 AM
To fix this issue If I have a list that varies in length each time and I want to sort it from lowest to highest, how would I do that? , I guess you are trying to do something like this:
code :
``````data_list = [-5, -23, 5, 0, 23, -6, 23, 67]
new_list = []

while data_list:
minimum = data_list[0]  # arbitrary number in list
for x in data_list:
if x < minimum:
minimum = x
new_list.append(minimum)
data_list.remove(minimum)

print new_list
``````

## How to sort a python list bidirectionally, by numbers in descending order and by alphabets in ascending order?

By : user2367923
Date : March 29 2020, 07:55 AM
seems to work fine The easiest way is to take advantage of sort stability and do the sort in two passes:
code :
``````>>> lot = [('hello', 25), ('hell', 4), ('bell', 4)]
>>> lot.sort(key=lambda r: r[0])
>>> lot.sort(key=lambda r: r[1], reverse=True)
>>> lot
[('hello', 25), ('bell', 4), ('hell', 4)]
``````
``````>>> lot = [('hello', 25), ('hell', 4), ('bell', 4)]
>>> sorted(sorted(lot, key=lambda r: r[0]), key=lambda r: r[1], reverse=True)
[('hello', 25), ('bell', 4), ('hell', 4)]
``````

## How to sort strings with letters and numbers in python by a specific order

By : albert
Date : October 12 2020, 11:00 AM
I hope this helps . There's no need to define your own function here. The stdlib function sorted takes a named parameter, key that can be used to specify the sort order. Try this:
code :
``````print( sorted( lst, key=lambda x:[order_list[0].index(y) for y in x] ))
``````