mutate dictionary or list

Paul McGuire ptmcg at
Wed Sep 8 19:17:37 CEST 2010

On Sep 7, 7:05 am, Baba <raoul... at> wrote:
> Hi
> I am working on an exercise which requires me to write a funtion that
> will check if a given word can be found in a given dictionary (the
> hand).
> def is_valid_word(word, hand, word_list):
>     """
>     Returns True if word is in the word_list and is entirely
>     composed of letters in the hand. Otherwise, returns False.
>     Does not mutate hand or word_list."""
> I don't understand this part: Does not mutate hand or word_list

I would re-read your exercise description.  hand is *not* a
dictionary, but is most likely a list of individual letters.
word_list too is probably *not* a dictionary, but a list of valid
words (although this does bear a resemblance to what people in
everyday life call a "dictionary").  Where did you get the idea that
there was a dictionary in this problem?

The "Does not mutate hand or word_list." is a constraint that you are
not allowed to update the hand or word_list arguments.  For instance,
you must not call word_list.sort() in order to search for the given
word using some sort of binary search.  You must not determine if all
the letters in word come from hand by modifying the hand list (like
dropping letters from hand as they are found in word).  There are ways
to copy arguments if you use a destructive process on their contents,
so that the original stays unmodified - but that sounds like part of
the exercise for you to learn about.

-- Paul

More information about the Python-list mailing list