如何从 xrange 列表中删除空格 - Python

How to remove spaces from a xrange list - Python

假设我有:

hello = list(xrange(100))
print hello

结果是:

1, 2, 3, 4, 5, 6, 7, 8, 9, 10...

我需要从列表中删除所有这些空格,这样它就可以像:

1,2,3,4,5,6,7,8,9,10...

由于 join 接受字符串对象,您需要将这些项目显式转换为字符串。例如:

hello = ','.join(list(xrange(100)))
TypeError: sequence item 0: expected string, int found

所以:

hello = xrange(100)
print ''.join([str(n) for n in hello])

注意不需要 list()