0

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

3 Answers3

0

You need to convert each item to string first ''.join(str(x) for x in list)

Ron Serruya
  • 3,988
  • 1
  • 16
  • 26
0

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))
    
azro
  • 53,056
  • 7
  • 34
  • 70
0

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.

Dev Sapariya
  • 151
  • 2
  • 9