very simple string to list function

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • v13tn1g
    New Member
    • Feb 2009
    • 31

    very simple string to list function

    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
  • v13tn1g
    New Member
    • Feb 2009
    • 31

    #2
    solved:) the problem

    Comment

    • bvdet
      Recognized Expert Specialist
      • Oct 2006
      • 2851

      #3
      I am glad you figured it out. Here's what I was going to suggest:
      Code:
      >>> s = "123456789"
      >>> [s[i:i+3] for i in range(0, len(s), 3)]
      ['123', '456', '789']
      >>>

      Comment

      Working...