Re: [Tutor] how to compare elements of 2 lists

2007-12-25 Thread tezlo
sith . [EMAIL PROTECTED] wrote:
 How can I determine if the elements in a are larger or smaller than
 the elements in b. 
  ..
 like 2 columns in excel, the third column would be
 a new list of boolean values. Can someone help please?  Thank you.

Hi,
in that case, you need to create the third column (list). Instead of
values, iterate over indices and use those to fetch the values, ie:
c = []
for i in range(min(len(a), len(b))):
  c.append(a[i]  b[i])

or using list comprehension:
c = [a[i]  b[i] for i in range(min(len(a), len(b)))]

tezlo
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] python CLI parser

2007-12-21 Thread tezlo
Martin Marcher [EMAIL PROTECTED] wrote:
 Hello,
 
 could you have a short review of my CLI package.

Hi,
it looks alright, it's really rather tiny. For one I could do with
spaces between functions for the sake of readability. And it would
make more sense to check the callback for being a callable once - while
registering it, instead of every time it's triggered. It's good to
program defensively, especially in a dynamic language like python,
where you can hardly stop anyone (yourself) from stuffing the dict
with uncallable garbage. But in this case, you deserve the exception as
it's up to you, the programmer, to register the commands. The check
should not be necessary if you write your program correctly.

As for CTRL+D, it fires an EOF. The manual for readline() says:
 A trailing newline character is kept in the string
 An empty string is returned when EOF is encountered immediately.
but you strip() the command (in two places) and lose the chance of
checking for that very case. Hope this helps.

tezlo
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor