471,595 Members | 1,090 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,595 software developers and data experts.

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 1590
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
reply views Thread by leo001 | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.