简体   繁体   English

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

[英]How to remove spaces from a xrange list - Python

Lets say I have: 可以说我有:

hello = list(xrange(100))
print hello

The result is: 结果是:

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

I need to remove all those spaces from the list so it can be like: 我需要从列表中删除所有这些空格,以便像这样:

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

Since join takes string objects, you need to convert those items explicitly to strings. 由于join需要字符串对象,因此您需要将这些项目显式转换为字符串。 For example: 例如:

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

So: 所以:

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

Note there is no need for the list() . 注意,不需要list()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM