473,383 Members | 1,870 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,383 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 11390
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...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.