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(
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
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
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)
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
"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