Sometimes we want to tackle some problem specifying properties of sequence of numbers consisting the integer. Then it is usefull to have function to join many integers to make a long integer. Most efficient way for tight loops is to stay in integers domain and not go through the string representation. Inspired by C++ question and my answer to it: http://www.daniweb.com/software-development/cpp/threads/425472/how-concatenate-number-in-c#post1819908
Joining integer numbers together to make new number
def together(*numbers):
b = numbers[-1]
for a in reversed(numbers[:-1]):
magnitude = 1
while b >= magnitude:
magnitude *= 10
b = magnitude * a + b
return b
print together(123, 456, 100, 789, 10, 999, 1000, 99)
TrustyTony 888 pyMod Team Colleague Featured Poster
Lucaci Andrew 140 Za s|n
TrustyTony 888 pyMod Team Colleague Featured Poster
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.