list example

2006-04-22 Thread PAolo
Hi, I wrote this small example to illustrate the usage of lists: even=[] odd=[] for i in range(1,10): if i%2: odd.append(i) else: even.append(i) print "odd: "+str(odd) print "even: "+str(even) numbers=even numbers.extend(odd) print "numbers:"+str(

Re: list example

2006-04-22 Thread Edward Elliott
No substantive problems. The str() calls are unnecessary, print calls list.__str__ already. You can replace the loop with list comprehensions or slices. Same result, a bit more succinct. See these pages for more: http://docs.python.org/lib/typesseq.html http://docs.python.org/tut/node7.html

Re: list example

2006-04-22 Thread Wojciech Muła
PAolo wrote: > any comment, suggestion? Is there something not elegant? Try this: even = range(10)[0::2] odd = range(10)[1::2] -- http://mail.python.org/mailman/listinfo/python-list

Re: list example

2006-04-22 Thread bearophileHUGS
PAolo>any comment, suggestion? Is there something not elegant?< Here you can see many little differences, some of them reflect just my style, but some other of them are Python standard style guidelines: even = [] odd = [] for i in xrange(1, 10): if i % 2: odd.append(i)

Re: list example

2006-04-23 Thread Paolo Pantaleo
2006/4/22, Edward Elliott <[EMAIL PROTECTED]>: > No substantive problems. The str() calls are unnecessary, print calls > list.__str__ already. You can replace the loop with list comprehensions or > slices. Same result, a bit more succinct. See these pages for more: > > http://docs.python.org/li

Re: list example

2006-04-25 Thread Andrew Koenig
"PAolo" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > for i in range(1,10): >if i%2: >odd.append(i) >else: >even.append(i) In 2.5 you'll be able to say for i in range(1,10): (odd if i%2 else even).append(i) Whether you