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
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)
Be a part of the DaniWeb community
We're a friendly, industry-focused community of 1.21 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.