将字符串拆分为三个字符的组 [英] Splitting a string into groups of three characters

查看:82
本文介绍了将字符串拆分为三个字符的组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述




是否有一个函数将字符串拆分成组,包含一个x

个字符数量?


Ex。

TheFunction(Hello World,3)


返回:


[''Hell'',''o W'','orl'','d'']

任何回复都会非常感激。


谢谢,

Hi,

Is there a function that split a string into groups, containing an "x"
amount of characters?

Ex.
TheFunction("Hello World",3)

Returns:

[''Hell'',''o W'',''orl'',''d'']
Any reply would be truly appreciated.

Thank You,

推荐答案

le ***** @ gmail.com 写道:


是否有将字符串拆分成组的函数,包含一个x
数量的字符?

TheFunction(Hello World,3)

返回:

[''Hell'',''o'',''orl'','d'']

任何回复都会得到真正的赞赏。

谢谢你,
Hi,

Is there a function that split a string into groups, containing an "x"
amount of characters?

Ex.
TheFunction("Hello World",3)

Returns:

[''Hell'',''o W'',''orl'',''d'']
Any reply would be truly appreciated.

Thank You,




也许,在那里的某个地方 - 你可以写一个你自己,像这样:


#未经测试

def nsplit(s,n):

返回[s [k:k] + n] for x in xrange(0,len(s),n)]



Maybe, somewhere out there -- you could write one yourself, like this:

# untested
def nsplit(s, n):
return [s[k:k+n] for k in xrange(0, len(s), n)]


嗯,你是第一个搜索食谱,或者是Vaults Parnassu,dmoz python

部分,pypackage:

http://aspn.activestate.com/ASPN/Coo.../Recipe/347689

http://www.codezoo.com/
http://www.vex.net/parnassus/
http://www.pypackage.org/packages

Um, you shd 1st search cookbook, or Vaults Parnassu, dmoz python
section, pypackage:

http://aspn.activestate.com/ASPN/Coo.../Recipe/347689

http://www.codezoo.com/
http://www.vex.net/parnassus/
http://www.pypackage.org/packages


谢谢你的帮助,

我想我会做几个这样的功能并找出

哪个是最快的。

Thank You, For your help,
I guess I will just make a couple of these functions and find out
which one is that fastest.


这篇关于将字符串拆分为三个字符的组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆