DEV Community

Discussion on: Dead Simple Python: Loops and Iterators

Collapse
 
ardunster profile image
Anna R Dunster

I see another comment thread addressed what I was wondering about the classified agents showing up if they weren't last ;)

For some reason I had the idea that lists and arrays were different in some functional way, but from your article it sounds they are functionally the same things, just with different vocabulary based on language?

I have a hard time grokking hashability. I've tried several times but something eludes me about the logic of why one thing is hashable and another isn't. I'd rather understand it than memorize it/look things up to check when it matters.

(Also, funny thing, OSX has grokking in the dictionary, but not hashable? what.)

Collapse
 
codemouse92 profile image
Jason C. McDonald • Edited

Yes, lists and arrays are effectively the same things. (There are some implementation differences internal to the language, mind you.)

Hashing means you perform some function, usually a form of one-way (lossy, as it were) encryption on the data to produce a (usually) unique value, often shorter than the original.

For example, here's the hashes for a few strings, according to Python's hash function. You'll notice they all produce a unique integer value, and all those integers are the same length.

"Hello" → 3483667490880649043
"Me" → 6066670828640188320
"Reverse the polarity of the neutron flow." → 7317767150724217908
"What evil lurks in the hearts of men? The shadow knows!" → -6411620787934941530

When two different input values have the same hash, that's known as a "hash collision", so any container that relies on a hash (such as Python's dictionaries) needs to be able to handle that situation.

For more information, watch this excellent explanation by the legendary @vaidehijoshi :

Collapse
 
ardunster profile image
Anna R Dunster

Thanks for the link, that's a great video and the visuals are quite helpful. Will check out the rest of her series, too.