William Park wrote:
> [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote:
>
>>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 apprec
I guess this question has already been thouroughly answered but here
is my version:
def split(string,n):
outlist=[]
for bottom in range(0,len(string),n):
top=min(bottom+n,len(string))
outlist.append(string[bottom:top])
return outlist
On 8/8/05, William Park <[EMAIL
[EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote:
> 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.
Look into 're' mo
Another solution derived from an old discussion about the same problem?
def takeBy(s, n):
import itertools
list(''.join(x) for x in itertools.izip(*[iter(s)]*n))
(Hoping len(s) % n = 0)
CyrilOn 8 Aug 2005 11:04:31 -0700, [EMAIL PROTECTED] <[EMAIL PROTECTED]
> wrote:Yes i know i made a mi
Yes i know i made a mistake,
>['Hell','o W','orl','d']
but you know what I mean lol,
I'll probly use
John Machin's
def nsplit(s, n):
return [s[k:k+n] for k in xrange(0, len(s), n)]
It seems fast, and does not require any imports.
But anyways, thank you for all your help, you rock! :)
--
Yes i know i made a mistake,
>['Hell','o W','orl','d']
but you know what I mean lol,
I'll probly use
John Machin's
def nsplit(s, n):
return [s[k:k+n] for k in xrange(0, len(s), n)]
It seems fast, and does not require any imports.
But anyways, thank you for all your help, you rpck! :)
--
import re
str = '123456789983qw'
re.findall("(.{3})", str)+[str[-(len(str) % 3):]]
[EMAIL PROTECTED] wrote:
> 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']
gene tani wrote:
> Um, you shd 1st search cookbook, or Vaults Parnassu, dmoz python
> section, pypackage:
>
> http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/347689
which includes e.g.
def each_slice_lol(listin,n):
"""non-overlapp'g slices, return (list of lists) """
len_listin=le
<[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
> Is there a function that split a string into groups, containing an "x"
> amount of characters?
There have been previous threads giving various solutions (which generally
are not specific to strings). You might find some some by sear
Thank You, For your help,
I guess I will just make a couple of these functions and find out
which one is that fastest.
--
http://mail.python.org/mailman/listinfo/python-list
Um, you shd 1st search cookbook, or Vaults Parnassu, dmoz python
section, pypackage:
http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/347689
http://www.codezoo.com/
http://www.vex.net/parnassus/
http://www.pypackage.org/packages
--
http://mail.python.org/mailman/listinfo/python-list
[EMAIL PROTECTED] wrote:
> 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,
>
Maybe, somewhere o
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,
--
http://mail.python.org/mailman/listinfo/python-list
13 matches
Mail list logo