Python String split by length:
some time we need to split string by length, sample code is given below
some time we need to split string by length, sample code is given below
def split_by_length(s,block_size): w=[] n=len(s) for i in range(0,n,block_size): w.append(s[i:i+block_size]) return w w=split_by_length("ABCDEFGHIJKLMNOPQRSTUVWXYZ",5) print w
Output:
['ABCDE', 'FGHIJ', 'KLMNO', 'PQRST', 'UVWXY', 'Z']
1 comments:
Post a Comment