Dinosaur Island Course 5 W1 -Exercise 4 question

Hello - any suggestions on correct syntax for list comprehension(?) to address error below
—> 54 single_example_ix = char_to_ix[[single_example_chars]]
55 X = [None] + single_example_ix
56

TypeError: unhashable type: ‘list’

(sorry but having little experience with Python i struggle with syntax:-(

1 Like

Your code there isn’t a list comprehension. char_to_ix is a dictionary. And you’ve nested two sets of square brackets, which confuses me.

A comprehension requires that you use a dictionary and a “for” statement, so that it automatically iterates through the dictionary.

Hello, I notice the grader passed me on Week 1 : Course 5 : Sequence Models, even though I did not get the required output for the final section.

Although my Python knowledge is slight, I would still like to learn why my code in the ‘model’ section was off. Since I cant post on Discourse, I paste it below, along with the (wrong) output which seems not to converge at all.

Any tips inputs to help me understand apprecated.

{mentor edit: image of code removed - not allowed by the Honor Code}

I think the main problem is in your single_example_ix code.
For each character in single_example_chars, you want to look it up in the char_to_ix dictionary.

So…
single_example_ix = [char_to_ix[c] for c in single_example_chars]

2 Likes

Also, please edit your message to remove the code. That will satisfy the course Honor Code.

Thanks Tom, note that I only emailed this to you, did not post on Discourse because of the code.

You need to initialise Y a bit differently to get the correct result. You don’t need all values of X.

thanks, yes, I am still new to Python, but searching for tips on internet, i was able to find the right syntax

thanks , my python knowledge still young, but this helped.