Use indexes

You're slicing the list, which return lists. Here, you should use indexes instead:

firstDigit = x[0]
lastDigit = x[-1]

Why is slicing wrong for you:

When you do x[0:1], you're taking the list of items from the beginning of the list to the first interval.

 item0, item1, item2, item3
^ interval 0
        ^ interval 1
              ^ interval 2 
                     ^ interval 3    

Doing x[0:2], for example, would return items 0 and 1.

Answer from Thomas Orozco on Stack Overflow
๐ŸŒ
Python Help
pythonhelp.org โ€บ tutorials โ€บ convert-list-to-int
How to convert a list to int in Python
September 23, 2024 - Before diving into the methods, itโ€™s essential to understand the basic concept of data types in Python. A list is a collection of items, which can be of different data types, while an integer is a whole number without a fractional component. Converting a list to an integer involves transforming the listโ€™s elements into a single numerical value.
๐ŸŒ
Medium
medium.com โ€บ @nawazmohtashim โ€บ converting-a-list-to-integer-in-python-exploring-methods-and-techniques-db527fcc583a
Converting a List to Integer in Python: Exploring Methods and Techniques | by Mohd Mohtashim Nawaz | Medium
December 13, 2023 - The reduce() function takes a binary function (here, a lambda function) and successively applies it to the elements of the list, effectively accumulating them into a single value. If the list contains numeric elements, the numpy library provides a concise way to convert a list to an integer.
๐ŸŒ
Java2Blog
java2blog.com โ€บ home โ€บ python โ€บ python list โ€บ convert list to integer in python
Convert List to Integer in Python [4 Ways] - Java2Blog
February 28, 2023 - Use list comprehension to convert each list item from integer type value to string type value; for instance, from [5, 6, 7] to ['5', '6', '7']. Use the join() method to join all the list items to make a single string value, such as from ['5', ...
๐ŸŒ
Script Everything
scripteverything.com โ€บ convert-list-to-integers-in-python-with-one-line-of-code
Change List Elements To Int In Python: 1 Line Of Code
As you can see trying to force conversion on an element that will not change to an integer using the int() method will produce a ValueError. This is where if itโ€™s a possibility your source list may contain elements that will not readily convert ...
๐ŸŒ
Python Help
pythonhelp.org โ€บ python-lists โ€บ how-to-convert-list-to-int-in-python
Convert List to Integer in Python
November 21, 2023 - To convert a list item to an integer, you can use the built-in int() function in python.
๐ŸŒ
YouTube
youtube.com โ€บ trinity software academy
how to convert list elements to int: python one-liner code - YouTube
This video explains about converting list elements to int data type in pythonusing 2 methods, each one-line code.1.using map2. list comprehensionLink for Bui...
Published: June 24, 2021
Views: 1K
Find elsewhere
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ python โ€บ python-converting-all-strings-in-list-to-integers
Converting all Strings in a List to Integers - Python - GeeksforGeeks
July 11, 2025 - map() function applies a given function to all elements in an iterable. Here, we use map(int, a) to convert each string in the list to an integer. ... List comprehension provides a more Pythonic and concise way to convert a list of strings to ...
๐ŸŒ
Medium
medium.com โ€บ @aleksej.gudkov โ€บ how-to-convert-numbers-in-a-list-using-the-int-function-e20425dface6
How to Convert Numbers in a List Using the int() Function | by UATeam | Medium
November 24, 2024 - The map() function applies int() to each element in the list. ... numbers = ["1", "2", "3", "4"] int_numbers = list(map(int, numbers)) print(int_numbers) # Output: [1, 2, 3, 4] If your list contains a mix of strings and numbers, you can filter ...
๐ŸŒ
Spark By {Examples}
sparkbyexamples.com โ€บ home โ€บ python โ€บ convert list of integer to an integer in python
Convert List of Integer to an Integer in Python - Spark By {Examples}
3 weeks ago - How to convert a list of integers to an integer by multiplying all values in a Python list? You can convert a list of integers into a single integer using
๐ŸŒ
YouTube
youtube.com โ€บ watch
How To Convert List To Integer In Python - YouTube
How To Convert List To Integer In Python? This tutorial answers that question. Converting a list to integer in Python consists of taking the list of numbers,...
Published: April 3, 2024
๐ŸŒ
Delft Stack
delftstack.com โ€บ home โ€บ howto โ€บ python โ€บ python convert list of strings to ints
How to Convert List of Strings to Integer in Python | Delft Stack
March 11, 2025 - Using list comprehension, we iterate over each string in the list and apply the int() function to convert it into an integer. The result is a new list called int_list, which contains the converted integers.
๐ŸŒ
YouTube
youtube.com โ€บ watch
Convert List Items To Int - Python - YouTube
In this video we'll see how to convert a list element into integers in very simple and easy way.Thanks for watching :)#Python
Published: August 27, 2021
๐ŸŒ
Finxter
blog.finxter.com โ€บ 5-best-ways-to-convert-a-python-list-to-an-integer
5 Best Ways to Convert a Python List to an Integer โ€“ Be on the Right Side of Change
February 20, 2024 - This compact code snippet combines a generator expression with reduce() to convert the list to an integer by iterating only once over the list elements. Method 1: Using int() with join(). Strengths: Simple and direct. Weaknesses: Requires converting integers to strings and back, which may be ...
๐ŸŒ
Finxter
blog.finxter.com โ€บ how-to-convert-a-string-list-to-an-integer-list-in-python
How to Convert a String List to an Integer List in Python โ€“ Be on the Right Side of Change
April 9, 2021 - The most Pythonic way to convert a list of strings to a list of ints is to use the list comprehension [int(x) for x in strings]. It iterates over all elements in the list and converts each list element x to an integer value using the int(x) built-in function.
๐ŸŒ
Finxter
blog.finxter.com โ€บ 5-best-ways-to-convert-list-elements-to-integers-in-python
5 Best Ways to Convert List Elements to Integers in Python โ€“ Be on the Right Side of Change
February 18, 2024 - The list comprehension iterates through str_list, converting each element to an integer and collecting the results into a new list, int_list. The ast.literal_eval() function can be used to evaluate a string containing a Python literal or container display into the corresponding Python datatype.