By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
439,986 Members | 1,568 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 439,986 IT Pros & Developers. It's quick & easy.

very simple string to list function

P: 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
Share this Question
Share on Google+
2 Replies


P: 31
solved:) the problem
Mar 16 '09 #2

bvdet
Expert Mod 2.5K+
P: 2,851
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.