pythonarraysintchars

Convert array of int to array of chars - Python


I am trying to convert a set literal of integers into that of chars.

For example, if the array {0,1} is given as an input, I would like to firstly check if the individual elements are chars and if not convert them into chars so that I get {'0', '1'}

So far I have tried:

for i in alpha:

    i = str(i)

Where alpha is my array. However this does not change the overall array alpha.

Can sometime please give me an idea of how I can do this.

Thanks in advance for any help


Solution

  • Use map function to convert a list of integres to list of strings , how ever map function retruns a map object so I used a list function to convert that to a list and assgin to first list (alpha) :

    alpha = [1,2,3,4]    
    alpha = list(map(str,alpha))
    alpha # ['1', '2', '3', '4']