469,271 Members | 1,320 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,271 developers. It's quick & easy.

very simple string to list function

31
the question that im wondering is how do i split into one list of str, say "123456789" into for every third value

so the output would be ['123' , '456' , '789']

thanks
Mar 16 '09 #1
2 1551
v13tn1g
31
solved:) the problem
Mar 16 '09 #2
bvdet
2,851 Expert Mod 2GB
I am glad you figured it out. Here's what I was going to suggest:
Expand|Select|Wrap|Line Numbers
  1. >>> s = "123456789"
  2. >>> [s[i:i+3] for i in range(0, len(s), 3)]
  3. ['123', '456', '789']
  4. >>> 
Mar 16 '09 #3

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

8 posts views Thread by York | last post: by
11 posts views Thread by greg.scharlemann | last post: by
4 posts views Thread by MrTang001 | last post: by
13 posts views Thread by na1paj | last post: by
4 posts views Thread by NT | last post: by
10 posts views Thread by =?utf-8?B?5Lq66KiA6JC95pel5piv5aSp5rav77yM5pyb5p6B | last post: by
1 post views Thread by =?ISO-8859-1?Q?Tor_Erik_S=F8nvisen?= | last post: by
4 posts views Thread by sagi | last post: by
1 post views Thread by CARIGAR | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.