Skip to content

Instantly share code, notes, and snippets.

@giuliano-oliveira
Last active February 12, 2023 19:54
Embed
What would you like to do?
Interesting python stuff

Interesting python stuff i found messing around with it

1 hash function is random for non non-primitive objects, and it's seed is reset each time the interpreter is ran

Example: python -c "print(hash('hello world'))" generates random numbers, while python -c "print(hash(4.2))" always returns a constant value

2 list.extend method updates itself each time the iterator is called

This code will run forever ( and eat all your RAM ): python -c "l = [1]; l.extend(i+1 for i in l)"

While this one won't python -c "l = [1]; l.extend([i+1 for i in l])"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment