Search code examples
pythonlistsplitarr

How to split a list that has ONLY ONE integer value in Python?


I want to split a value in a list and make it two values.

arr = [10]

The array should turn in to:

arr = [1,0]

Solution

  • Use list comprehension with two iterations:

    >>> [int(x) if x.isdigit() else x for y in arr for x in str(y)]
    [1, 0]
    >>>