将整数列表转换为整数python

Md.*_*fee 1 python python-3.x

我有一个整数列表:

lists = [8,7,2]
Run Code Online (Sandbox Code Playgroud)

我希望它是:

result = 872
Run Code Online (Sandbox Code Playgroud)

我可以通过以下方式做到这一点:

result = 0
for count, i in enumerate(reversed(lists)):
    result += i*(10**count)
Run Code Online (Sandbox Code Playgroud)

有用。但我认为应该有另一种更好更快的方法。提前致谢

小智 5

你可以试试这个

int("".join(list(map(str,lists))))
Run Code Online (Sandbox Code Playgroud)

将所有整数映射到字符串,然后加入它们并将它们转换回整数。