Re: [Tutor] Question about list

2006-04-10 Thread Hoffmann
--- Matthew White <[EMAIL PROTECTED]> wrote: > Hi Hoffman, > > It is often useful to use the "for" construct to > process items in a list. > e.g.: > > >>> list1 = [ 'spam!', 2, ['Ted', 'Rock']] > >>> for item in list: > ...print item > spam! > 2 > ['Ted', 'Rock'] > > If you pass a list to

Re: [Tutor] Question about list

2006-04-10 Thread Hoffmann
--- Terry Carroll <[EMAIL PROTECTED]> wrote: > On Mon, 10 Apr 2006, Hoffmann wrote: > > > Hello, > > > > I have a list: list1 = [ 'spam!', 2, ['Ted', > 'Rock'] > > ] > > and I wrote the script below: > > > > i = 0 > > while i < len(list1): > > print list1[i] > > i += 1 > > > > Ok. Thi

Re: [Tutor] Question about list

2006-04-10 Thread Danny Yoo
On Mon, 10 Apr 2006, Hoffmann wrote: > I also would like to print the length of each element > of that list: > > spam! = 1 element > 2 = 1 element > ['Ted', 'Rock'] = 2 elements > > Could anyone, please, give me some hints? The problem is slightly weird, just because you need to clarify what i

Re: [Tutor] Question about list

2006-04-10 Thread Terry Carroll
On Mon, 10 Apr 2006, Hoffmann wrote: > Hello, > > I have a list: list1 = [ 'spam!', 2, ['Ted', 'Rock'] > ] > and I wrote the script below: > > i = 0 > while i < len(list1): > print list1[i] > i += 1 > > Ok. This script will generate as the output each > element of the original list, on

Re: [Tutor] Question about list

2006-04-10 Thread Hoffmann
--- John Fouhy <[EMAIL PROTECTED]> wrote: > Hi Hoffmann, > > On 11/04/06, Hoffmann <[EMAIL PROTECTED]> wrote: > > I have a list: list1 = [ 'spam!', 2, ['Ted', > 'Rock'] ] > > and I wrote the script below: > > > > i = 0 > > while i < len(list1): > > print list1[i] > > i += 1 > > Have you

Re: [Tutor] Question about list

2006-04-10 Thread Matthew White
Hi Hoffman, It is often useful to use the "for" construct to process items in a list. e.g.: >>> list1 = [ 'spam!', 2, ['Ted', 'Rock']] >>> for item in list: ...print item spam! 2 ['Ted', 'Rock'] If you pass a list to the len() function, it will return the number of elenents in the list. e.g

Re: [Tutor] Question about list

2006-04-10 Thread Hoffmann
--- Adam <[EMAIL PROTECTED]> wrote: > On 10/04/06, Hoffmann <[EMAIL PROTECTED]> wrote: > > Hello, > > > > I have a list: list1 = [ 'spam!', 2, ['Ted', > 'Rock'] > > ] > > and I wrote the script below: > > > > i = 0 > > while i < len(list1): > > print list1[i] > > i += 1 > > > > Ok. This s

Re: [Tutor] Question about list

2006-04-10 Thread Adam
On 10/04/06, Hoffmann <[EMAIL PROTECTED]> wrote: > Hello, > > I have a list: list1 = [ 'spam!', 2, ['Ted', 'Rock'] > ] > and I wrote the script below: > > i = 0 > while i < len(list1): > print list1[i] > i += 1 > > Ok. This script will generate as the output each > element of the original

Re: [Tutor] Question about list

2006-04-10 Thread John Fouhy
Hi Hoffmann, On 11/04/06, Hoffmann <[EMAIL PROTECTED]> wrote: > I have a list: list1 = [ 'spam!', 2, ['Ted', 'Rock'] ] > and I wrote the script below: > > i = 0 > while i < len(list1): > print list1[i] > i += 1 Have you read about "for" loops? The pythonic way of looping through a list

[Tutor] Question about list

2006-04-10 Thread Hoffmann
Hello, I have a list: list1 = [ 'spam!', 2, ['Ted', 'Rock'] ] and I wrote the script below: i = 0 while i < len(list1): print list1[i] i += 1 Ok. This script will generate as the output each element of the original list, one per line: spam! 2 ['Ted', 'Rock'] I also would like to print