[Tutor] Searching a list for a value, was Re: (no subject)
Peter Otten
__peter__ at web.de
Wed Feb 12 04:36:11 EST 2020
David L Neil via Tutor wrote:
> Apologies to OP, in that somewhat different topical interest.
>
>
> On 11/02/20 10:59 PM, Peter Otten wrote:
> ...
>
>> your suggestion looks a bit like overengineering ;)
>
> It's a common problem in training.
>
> On the one hand we (trainers) try to gently guide trainees 'into' a
> solution - IIRC the OP even said 'has to use an if-statement (albeit
> your (advanced Python) solution both cleaner and more efficient!).
I was addressing Collisio, not the OP. IMO Collisio's solution is deficient,
and a beginner like the OP is unlikely to recognize that, under its pomp and
circumstance ;)
Had Collisio suggested something like
def list_contains_value(items, value):
for item in items:
if item == value:
return True
return False
that would have been fine by me.
It uses basic constructs like if... and for..., and even if the OP has not
been introduced to functions yet they will probably follow soon.
You can see pythonic iteration and can argue about what happens as the list
grows (big O). You can also have a look at duck typing: what happens if you
pass a string or set instead of a list? Is it a good idea to use the
function with sets?
In short, a beginner can learn a lot from code that no one who is a bit more
advanced would write or use.
> On the other, this sort of 'hinting' (and likely the use of published
> rubrics) does seem to 'steer' literal-minded people to limit their
> review of the material covered to-date.
>
> (Nothing new/out-of-the-ordinary: as students, many of us develop(ed)
> the strategy to trying to double-guess what the tutor/examiner was
> 'expecting', and customising our answers accordingly!)
>
> Thus, thinking along such lines as: 'I should include an if, a for, and
> show how advanced I am with a context manager...'
>
>
> These days, and not necessarily in-agreement with colleagues, I'm
> inclined against offering specific "use an if" advice - in the same way
> that when starting to develop a system one is wise not to impose
> artificial limits or pre-judge 'the best' solution (as in "must involved
> 'xyz' package/system/hardware/latest-shiny-object")!
>
> If trainees exhibit anxiety, then the course is to ask some questions
> which invite thinking about the material-covered.
> (and part of the 'learning contract' is to NEVER set a challenge which
> requires 'stuff' that hasn't been covered - although within that
> guideline, many trainees are surprised to discover that "reading" is
> part of their learning, and therefore "covered"!)
>
> Do you have other ideas or advice? I'll be interested to consider...
>
>
> Disclaimer: my training is in topics other than Python.
More information about the Tutor
mailing list