In last line when you print it,even though you're using comma after print ,It will create a space there!
Concatenate each character in new string(define an empty string) then return it
Your second code works fine ,except last line..
str(x) # this is '[1,2,3]' now not "123"
You can use
join() method on your final list to convert it back to string..not