Re: Create list from string

2008-06-13 Thread ericdaniel
Hi Chris, Thank you very much, that was exactly what I needed. Eric On Jun 13, 9:29 am, Chris <[EMAIL PROTECTED]> wrote: > On Jun 13, 4:15 pm, ericdaniel <[EMAIL PROTECTED]> wrote: > > > Hi, > > > I'm new to Python and I need to do the following: > > > from this:   s = "978654321" > > to this :

Re: Create list from string

2008-06-13 Thread John Machin
On Jun 14, 12:15 am, ericdaniel <[EMAIL PROTECTED]> wrote: > Hi, > > I'm new to Python and I need to do the following: > > from this: s = "978654321" > to this : ["978", "654", "321"] > > Any help is appreciated > Homework? Have you read the Python tutorial (section 3.1.2 Strings)? -- http

Re: Create list from string

2008-06-13 Thread Peter Otten
ericdaniel wrote: > I'm new to Python and I need to do the following: > > from this: s = "978654321" > to this : ["978", "654", "321"] Use a loop: >>> s = "978654321" >>> items = [] >>> for start in range(0, len(s), 3): ... items.append(s[start:start+3]) ... >>> items ['978', '654',

Re: Create list from string

2008-06-13 Thread Chris
On Jun 13, 4:15 pm, ericdaniel <[EMAIL PROTECTED]> wrote: > Hi, > > I'm new to Python and I need to do the following: > > from this:   s = "978654321" > to this :      ["978", "654", "321"] > > Any help is appreciated > > Thanks, > > Eric What you could do is iterate over the string appending the

Re: Create list from string

2008-06-13 Thread Ben Sizer
On Jun 13, 3:15 pm, ericdaniel <[EMAIL PROTECTED]> wrote: > Hi, > > I'm new to Python and I need to do the following: > > from this:   s = "978654321" > to this :      ["978", "654", "321"] What are your criteria for splitting this string? Every 3 characters? If there isn't an even multiple of 3,