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 8053373
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T07:49:28+00:00 2026-06-05T07:49:28+00:00

I am new to Python. First, the code is supposed to take an input

  • 0

I am new to Python.
First, the code is supposed to take an input (in the form of “x/y/z” where x,y, and z are any positive integer) and split it into three different variables.

input = raw_input()
a, b, c = input.split("/", 2)

I want the second part of my code to take these three variables and sort them based on their numerical value.

order = [a, b, c]
print order
order.sort()
print order

While this works perfectly for most inputs, I have found that for inputs “23/9/2” and “43/8/2” the output has not been sorted so is not returned in the correct order. Any thoughts as to what could be causing inputs such as these to not work?

  • 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-06-05T07:49:29+00:00Added an answer on June 5, 2026 at 7:49 am

    The issue is that you are sorting strings, and expecting them to be sorted like integers. First convert your list of strings to a list of ints if you would like numerical sorting.

    >>> sorted(['23', '9', '2'])
    ['2', '23', '9']
    >>> sorted(map(int, ['23', '9', '2']))
    [2, 9, 23]
    

    Here is how you could rewrite your code:

    input = raw_input()
    a, b, c = map(int, input.split("/", 2))
    order = [a, b, c]
    print order
    order.sort()
    print order
    

    If you need to convert them back to strings, just use map(str, order). Note that on Python 2.x map() returns a list and on 3.x it will return a generator.

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

Sidebar

Related Questions

I am somewhat new to Python. I need two functions. The first is supposed
First of all, I am new to python/nltk so my apologies if the question
I am new to programming and am learning Python as my first language. I
I'm fairly new to both Django and Python. This is my first time using
I'm pretty new to Python, and I want to develop my first serious open
Here are three pieces of similar code, the first two run fine, the last
I am still new to Python and have been reviewing the following code not
I'm new to programing, this is my first python-gtk applet and I'm trying to
Hi there First of all just let me say that I'm new in Python
I have a user input form here: http://www.7bks.com/create (Google login required) When you first

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.