Skip to content

Instantly share code, notes, and snippets.

@giuliano-macedo
Last active November 7, 2023 14:50
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save giuliano-macedo/4850dc70dd0ba8fe32cc6c0274c63914 to your computer and use it in GitHub Desktop.
Save giuliano-macedo/4850dc70dd0ba8fe32cc6c0274c63914 to your computer and use it in GitHub Desktop.
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