Search code examples
pythonlistintegerdigit

Joining a list of string digits to create an integer Python 3


How can I convert this:

['2', '3', '1', '4', '1', '4', '2', '3', '3', '2', '4', '1', '4', '1', '3', '2']

into this

2314142332414132

I've tried using the .join method, but I'm quite new to Python and need some help using it. I've also tried working with re.sub, string.replace, but none of them worked. Any help?


Solution

  • Try this:

    values = ['2', '3', '1', '4', '1', '4', '2', '3', '3', '2', '4', '1', '4', '1', '3', '2']
    value = ''.join(values)
    

    If you want to have an int value, you can cast the resulting string to int:

    value = int(value)