I have created a sqlite database which has a table which stores temperature values. The temperature values are written to the database in ascending order for the first time. Then I read the temperature values from the database into a list and then add that list to a combo box to select temperatures - works fine.
The resulting list is, say:
templist = ['25', '50', '100', '150', '200', '250', '300'].
Then I add a new temperature value, say, '33' to the database.
It gets appended to the end of the table. If I read the temperatures now, the list will become:
['25', '50', '100', '150', '200', '250', '300', '33'].
If I do templist.sort()
or sorted(templist)
, the end result is
['150', '200', '25', '250', '300', '33', '50']
Is there any simple way to sort the list in ascending order so that I get:
['25', '33', '50', '100', '150', '200', '250', '300']
See Question&Answers more detail:
os