Python convert Tuple to Integer

前端 未结 8 579
心在旅途
心在旅途 2021-01-02 03:10

Is there any function that can convert a tuple into an integer?

Example:

input = (1, 3, 7)

output = 137
8条回答
  •  -上瘾入骨i
    2021-01-02 03:42

    Just another way to do it

    >>> sum(n*10**i for (i,n) in enumerate(input[::-1]))
    137
    

    and yet another

    >>> int(str(input).translate(None,'(,) '))
    137
    

提交回复
热议问题