Splitting a string into groups of three characters

Maksim Kasimov maksim.kasimov at gmail.com
Mon Aug 8 03:34:54 EDT 2005


import re
str = '123456789983qw'
re.findall("(.{3})", str)+[str[-(len(str) % 3):]]

lemon97 at gmail.com 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,
> 


-- 
Best regards,
Maksim Kasimov
mailto: maksim.kasimov at gmail.com



More information about the Python-list mailing list