473,395 Members | 1,948 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

removing a digit from a integer

i want to know how to remove a digit from an integer and place that digit at the beginning of the number. I know how to do it in a list but am not sure how to do in without creating a list.
eg.
digits(123)
>>>312
Feb 27 '14 #1
1 11399
bvdet
2,851 Expert Mod 2GB
This uses a str object, but not a list:
Expand|Select|Wrap|Line Numbers
  1. >>> i = 123
  2. >>> s = str(i)
  3. >>> int(s[-1]+s[:-1])
  4. 312
  5. >>> 
This doesn't use any type of sequence:
Expand|Select|Wrap|Line Numbers
  1. i = 123456789
  2. ii = i
  3. j = 0
  4. while ii:
  5.     ii, k = divmod(ii, 10)
  6.     j += 1
  7. n, x = divmod(i, 10)
  8. print x * 10**(j-1) + n
Feb 27 '14 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

5
by: Bunyip Bluegum | last post by:
I have a text field in a form which I need to check to see that only a 4-digit integer has been entered. The field has MAXLENGTH=4 and I'm using this to check for length: function...
38
by: Alan | last post by:
I want to change a 3 digits integer to characters, how can i do that? the 3 digits integer maybe 123, 23 or 3 I want to change the integer to "123", " 23" or " 3" thx
8
by: Candace | last post by:
I am using the following code to pick off each digit of a number, from right to left. The number I am working with is 84357. So for the first iteration it should return the number 7 and for the...
3
by: PeyYang | last post by:
Hi This spring I'm taking a Java coures and I need some help if posseble. I have this assignment and he needs me to use the modulus in the code: Q:Your application should read a four-digit...
7
by: southernsunsations | last post by:
/******************************************************************\ * * * * Date: 09.06.2007 ...
14
by: thehobbit | last post by:
Hi, Could anyone give ideas on how to add 4 20 digit numbers in ANSI C and pass the result back to a calling program in COBOL? We were able to add up to 15 digit numbers without any problems,...
5
by: toralf | last post by:
Hello, I'm wondering how I can test whether a field matches a 10-digit integer within DB2. -- MfG/Sincerely Toralf Förster pgp finger print: 7B1A 07F4 EC82 0F90 D4C2 8936 872A E508 7DB6...
5
by: =?Utf-8?B?Y2hyaXNiZW4=?= | last post by:
Hi, I try to use an integer to pass 4 kinds of information. Each kind may have 5 types. I plan to use an integer like 2034, while 2 0 3 4 are corresponding to the type of each kind. I am...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.