I want to convert a list to string e.g list = [1, 2, 3, 4, 5, 6, 7, 8, 9, 0]
would be list = '1234567890'
I tried ''.join()
but this doesn't work since the list consists of integers
I want to convert a list to string e.g list = [1, 2, 3, 4, 5, 6, 7, 8, 9, 0]
would be list = '1234567890'
I tried ''.join()
but this doesn't work since the list consists of integers
You need to convert each item to string first
''.join(str(x) for x in list)
As you have a list of int
values = [1, 2, 3, 4, 5, 6, 7, 8, 9, 0]
(don't use builtin list
for naming) you may convert them to str
before with
a generator expression
result = ''.join(str(x) for x in values)
map
function
result = ''.join(map(str, values))
you can try:
lst=[1,3,2,4,4]
list_string=''
for i in lst:
list_string+=str(i)
print(list_string)
note: you can not use list as variable.