in python sorted
works like you want with integers:
>>> sorted([10,3,2])
[2, 3, 10]
it looks like you have a problem because you are using strings:
>>> sorted(['10','3','2'])
['10', '2', '3']
(because string ordering starts with the first character, and "1" comes before "2", no matter what characters follow) which can be fixed with key=int
>>> sorted(['10','3','2'], key=int)
['2', '3', '10']
which converts the values to integers during the sort (it is called as a function - int('10')
returns the integer 10
)
and as suggested in the comments, you can also sort the list itself, rather than generating a new one:
>>> l = ['10','3','2']
>>> l.sort(key=int)
>>> l
['2', '3', '10']
but i would look into why you have strings at all. you should be able to save and retrieve integers. it looks like you are saving a string when you should be saving an int? (sqlite is unusual amongst databases, in that it kind-of stores data in the same type as it is given, even if the table column type is different).
and once you start saving integers, you can also get the list back sorted from sqlite by adding order by ...
to the sql command:
select temperature from temperatures order by temperature;