3

I have a list xline. It is initialized and then appended. But I am getting an error when I run?

xline = []
---#append
----
print (''.join(xline)) # Convert list into string

Run time error

    print (''.join(xline)) # Convert list into string
TypeError: sequence item 0: expected string, int found

What is wrong?

user5331677
  • 409
  • 3
  • 6
  • 12

1 Answers1

5

You can use str() to transform each element:

print ''.join([str(x) for x in xline])
dnozay
  • 23,846
  • 6
  • 82
  • 104
dursk
  • 4,435
  • 2
  • 19
  • 30
  • The above method is more versatile than the map method as I was able to format. I liked map for simplicity but lacks formatting option or I do not know how to format with map. – user5331677 Oct 05 '15 at 05:22