Search code examples
pythonstringnested-lists

Convert a list of strings to a Nested list of integers


I have this output: ['0100', '0100'] and I wanted to have something like this [[0,1,0,0],[0,1,0,0]].

How can I do?


Solution

  • Try:

    lst = ["0100", "0100"]
    
    out = [[int(ch) for ch in s] for s in lst]
    print(out)
    

    Prints:

    [[0, 1, 0, 0], [0, 1, 0, 0]]