3 ms·
You'd probably want 'return len(str)', if this is Python? In any case, for some applications this is indeed a great hash function. Programs like rmlint use it
by eru 7mo ago
You'd probably want 'return len(str)', if this is Python?
In any case, for some applications this is indeed a great hash function. Programs like rmlint use it as part of their checks for duplicate files: if files have different lengths, they can't have the same content after all.
- andai 7mo agoRe: missing return keyword Actually, in Python, None is a valid key... (I'm so sorry. JavaScript has ruined me.)
- Sharlin 7mo agoYes, too much Rust :D Eliding the `return` becomes so intuitive after a while that you sort of forget that most other languages require it.
- eru 7mo agoHaskell and the Lisps also work like this.
- Sharlin 7mo agoYes, I know, it's the natural way to do it in functional programming. Honestly I doubt there are any FP languages that don't do it like that.
- eru 7mo agoI like that Rust, just like Lisp and Haskell et al also allow any block to return a value, not just functions. So if-then-else and loops etc can do that. It be nice if Python could do that. Perhaps I should hack up Python to allow that. Would be an interesting little project.