tags:

views:

113

answers:

3
b=','.join([1,2,3,4,5])
print b

In your answers, please try to use code examples rather than text, because my English is not very good. Thank you.

+4  A: 

The join function expects strings not integers, if you did b=','.join(["1","2","3","4","5"]) instead it works.

Here's the consoles output:

>>> b=','.join(["1","2","3","4","5"])
>>> print b
1,2,3,4,5
>>>
johnnyArt
+6  A: 
b = ','.join(map(str, [1,2,3,4,5]))
# => '1,2,3,4,5'

Python doesn't automatically turn the ints into strings--you have to convert them to strings first, then join them.

Jordan
+6  A: 

anystring.join takes an iterable of STRINGS, not one of integers, which is what you're passing to it!

So, use ','.join(str(x) for x in range(1, 6)) or the like.

Alex Martelli