Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Supported by

Displaying items in a SketchPad from a Python dictionary.

edited February 9 in OpenSesame

Hi Folks,

I'm creating a dictionary in python from which I plan to reference and retrieve stimuli for display.

Attached is a file with a minimum replication of what I'm doing and the error in question.

#

In my inline script:

I first create a list of of text stimuli, shuffle it, and then change that list into a tuple. I start with a list because shuffle doesn't work with a tuple (I've also tried using just a tuple foregoing the shuffle but get the same error described below).

I also create a dictionary with keys that match the tuple items.

I then use a sketch pad with the following:

[=Alpha_Stim_Contents.get(\[Alpha_Stim\[Alpha_Count\]\])]

but I keep getting this error: TypeError: unhashable type: 'list'

The code is supposed to display the item in the dictionary that matches the item number in 'Alpha_Stim'.

#

I've checked the type of object and it is reporting as a tuple. I've also run the code in a Python interpreter and it seems to work fine.

Any idea why I can't get this to work? I assume I'm overlooking something obvious or haven't converted Python code correctly to OpenSesame in the SketchPad.

Thanks as always for your time,

Boo.

Comments

  • edited February 7

    I didn't escape backslashes when pasting the code above. It should look like this:

    [=Alpha_Stim_Contents.get(\[Alpha_Stim\[Alpha_Count\]\])]

    Thanks,

    Boo.

  • Hi Folks,

    Please excuse the bump.

    Any ideas on this error?

    Thanks,

    Boo.

  • Hi Boo,

    I can never remember how to write complex commands in a sketchpad. However, I adapted your script a bit (adding an inline_script before the sketchpad that selects the item of your dictionary). Is that good enough for you?

    Eduard

    Thanked by 1booradley
  • Hi Eduard,

    That's a much more preferable way of doing things actually. I shall KIC (Keep it Code!) from now on.

    Thanks for your help!

    Boo.

  • The hash() is a built-in python method, used to return a unique number . This can be applied to any user-defined object which won’t get changed once initialized. This property is used mainly in dictionary keys .

    TypeError: unhashable type: 'list' usually means that you are trying to use a list as an hash argument. This means that when you try to hash an unhashable object it will result an error. For ex. when you use a list as a key in the dictionary , this cannot be done because lists can't be hashed. The standard way to solve this issue is to cast a list to a tuple .

    http://net-informations.com/python/iq/unhashable.htm

Sign In or Register to comment.