Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7670657
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T15:52:20+00:00 2026-05-31T15:52:20+00:00

I have created an SQLite database which has a table which stores temperature values.

  • 0

I have created an 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. It 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 a simple way to sort the list in ascending order, so that I get the following?

['25', '33', '50', '100', '150', '200', '250', '300']
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T15:52:22+00:00Added an answer on May 31, 2026 at 3:52 pm

    The recommended approach in this case is to sort the data in the database, adding an ORDER BY at the end of the query that fetches the results. Something like this:

    SELECT temperature FROM temperatures ORDER BY temperature ASC;  -- ascending order
    SELECT temperature FROM temperatures ORDER BY temperature DESC; -- descending order
    

    If for some reason that is not an option, you can change the sorting order like this in Python:

    templist = [25, 50, 100, 150, 200, 250, 300, 33]
    sorted(templist, key=int)               # ascending order
    > [25, 33, 50, 100, 150, 200, 250, 300]
    sorted(templist, key=int, reverse=True) # descending order
    > [300, 250, 200, 150, 100, 50, 33, 25]
    

    As has been pointed in the comments, the int key (or float if values with decimals are being stored) is required for correctly sorting the data if the data received is of type string, but it’d be very strange to store temperature values as strings. If that is the case, go back and fix the problem at the root, and make sure that the temperatures being stored are numbers.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a table login2 in /data/data/sankalp.jain.shre/databases/loginfinal.db. The database has been created correctly which
In Android, I created an SQLite database containing one table, which in turn has
I have an sqlite database on android created like this: sqlite> .schema CREATE TABLE
I have created a application which uses Sqlite database. Now i wanted to deploy
I have created a database in mesa sqlite software which creates a .rdb format
I have created the Simple Application of the sqlite database. In which i am
I am new to using the SQLite database in iphone apps. I have created
I have an SQLite database. I created the tables and filled them with a
I have made this code to open a database(created in SQLite browser) stored in
I have creating a login form where I have created sqlite database,in this I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.