[Tutor] error message
Michael Emperador
memperad@iaware.org
Fri, 20 Jul 2001 13:52:57 -0700 (PDT)
On Fri, 20 Jul 2001, Danny Yoo wrote:
> Date: Fri, 20 Jul 2001 12:44:48 -0700 (PDT)
> From: Danny Yoo <dyoo@hkn.eecs.berkeley.edu>
> To: Michael Emperador <memperad@iaware.org>
> Cc: tutor@python.org
> Subject: Re: [Tutor] error message
>
> On Fri, 20 Jul 2001, Michael Emperador wrote:
>
> > def curr_cust(seq1,seq2):
> > cust = []
> > for x in seq1:
> > if x in ("seq2"):
> > cust.append(x)
> > return cust
>
> Let me make sure I understand what you want curr_cust() to do first. Do
> you want it to do something like this?
>
> ###
> > curr_cust(['mary', 'had', 'lamb', 'chops'],
> ['mary', 'had', 'a', 'little', 'lamb'])
> ['mary', 'had', 'lamb']
> ###
>
> (Sorry about the gruesome example --- it's lunchtime for me. *grin*)
>
> If so, then what you'll want to do is check if x is inside seq2.
> Assuming this is what you want, the correction will look like this:
>
> ###
> def curr_cust(seq1,seq2):
> cust = []
> for x in seq1:
> if x in seq2:
> cust.append(x)
> return cust
> ###
Daniel,
I did do exactly this and came up with the same error. I actually sent
the wrong snippet of code--I was trying to modify based on some
suggestions. The script is actually a cgi script I am attempting to
write. The form dictionary is what is stored in cgi.FieldStorage. I
wanted to simplify to test my first function. I've based the function on
an example in Learning Python. I'm still at a loss.
Thanks for your help
Mike
> >
> Another way we could define this function would be to use list
> comprehensions, like this:
>
> ###
> def curr_cust(seq1, seq2):
> return [x for x in seq1 if x in seq2]
> ###
>
> If you have more questions, please feel free to ask. Good luck to you!
>
>
> _______________________________________________
> Tutor maillist - Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor
>