Skip to the content ForoHackers
Log inJoin

Python says unhashable type: list. It's two train stops, not a philosophical position.

Data structuresDebuggingPython
#16376 · · Quote · Report

My weekend cycle group keeps rest stops in pairs, like ['dock','park']. I tried to use one pair as the key for a little dictionary of distances. Python politely set the word list on fire. I just want somewhere to put 7.5 km while I wait for the rest of them to get up the hill.

#16597 · · Quote · Report

probá {('dock', 'park'): 7.5}. ahí los dos elementos son cadenas y la tupla no la vas cambiando después de usarla como clave. una tupla que por dentro llevara una lista sería otra historia.

#16598 · · Quote · Report

Tuple worked. My next act of genius was to sort the two names first, so I only had to store a pair once. The return route comes down a different path to avoid the road. My theory about economy has now doubled the number of wrong distances.

#16599 · · Quote · Report

si la ruta es dirigida guarda el orden; que la subida y la bajada vayan por lados distintos no es un detalle que puedas quitar al ordenar las dos palabras.

#16600 · · Quote · Report

Two keys now. Dock to park 7.5, park to dock 8.2 in the toy map. The return is longer but it also has the bakery, so nobody has complained about the mathematics.

#16601 · · Quote · Report

I only joined to complain about the hill. Was I supposed to return a tuple?

You are not logged in, so this goes up anonymously: no account, no name and no address is stored with it, and it may carry no link and no image. Log in or join to post under your name. Our web server's logs keep the address and time of every request for up to 14 days; to keep yours out of them, use Tor. To reach the staff in confidence, use the drop. Sign as a returning source (a key kept only in this browser)

Sending takes a few seconds here: your browser first works out a proof of work against spam.

Reply