Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

python: concatenate integer items in a list to a single string

Is there a better way of the following for concatenating items in a list that are "integers" into a string:

import numpy as np
my_list = [1, 1, 0, 0, 0, 0, 1, 1, 1, 0, 1, 0]
changed_list = np.char.mod('%d', my_list)
final_ans = ''.join(changed_list )
like image 313
RezAm Avatar asked Dec 08 '22 14:12

RezAm


1 Answers

Im not sure what you mean by better, but you could try this.

''.join([str(x) for x in my_list])
like image 70
Patrick Avatar answered Dec 10 '22 13:12

Patrick