{"id":18471,"date":"2021-08-26T10:39:07","date_gmt":"2021-08-26T05:09:07","guid":{"rendered":"https:\/\/python-programs.com\/?p=18471"},"modified":"2021-11-22T18:37:16","modified_gmt":"2021-11-22T13:07:16","slug":"python-program-to-sort-digits-of-a-number-in-ascending-order","status":"publish","type":"post","link":"https:\/\/python-programs.com\/python-program-to-sort-digits-of-a-number-in-ascending-order\/","title":{"rendered":"Python Program to Sort digits of a Number in Ascending Order"},"content":{"rendered":"

In the previous article, we have discussed Python Program to Count the Number of Odd and Even Digits<\/a>
\nThe task is to sort the digits in ascending order given a number N. Print the new number after removing the leading zeroes.<\/p>\n

join() method in python:<\/strong><\/p>\n

The join() method in Python can be used to convert a List to a String.<\/p>\n

Iterables such as Lists, Tuples, Strings, and others are accepted as parameters for the join() process.<\/p>\n

Examples:<\/strong><\/p>\n

Example1:<\/strong><\/p>\n

Input:<\/strong><\/p>\n

Given Number = 4561230008<\/pre>\n

Output:<\/strong><\/p>\n

The sorted digits in ascending order of a given number 4561230008 after removal of leading zeros =\r\n1234568<\/pre>\n

Example2:<\/strong><\/p>\n

Input:<\/strong><\/p>\n

Given Number = 34879010<\/pre>\n

Output:<\/strong><\/p>\n

The sorted digits in ascending order of a given number 34879010 after removal of leading zeros =\r\n134789<\/pre>\n

Program to Sort digits of a Number in Ascending Order in Python<\/h2>\n

Below are the ways to get sorted digits in ascending order of a given number after the removal of leading zeros:<\/p>\n