Reputation: 9
I'd like to convert a list of integers to a singe variable.
I tried this (found on another question):
r = len(message) -1
res = 0
for n in message:
res += n * 10 ** r
r -= 1
This does not work for me at all.
I basically need this:
message = [17, 71, 34, 83, 81]
(This can vary in length as I use a variable to change each one) To convert into this:
new_message = 1771348381
Upvotes: 0
Views: 31
Reputation: 81604
A combination of join
, map
and str
will do.
message = [17, 71, 34, 83, 81]
new_message = int(''.join(map(str, message)))
# 1771348381
Upvotes: 3