Skip to content

Instantly share code, notes, and snippets.

@simeonwillbanks
Last active September 23, 2015 17:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save simeonwillbanks/592850 to your computer and use it in GitHub Desktop.
Save simeonwillbanks/592850 to your computer and use it in GitHub Desktop.
#Python mogrify
Python 2.5.1 (r251:54863, Feb 6 2009, 19:02:12)
[GCC 4.0.1 (Apple Inc. build 5465)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> def mogrify(li):
... for i, v in enumerate(li):
... li[i] = v * 2
...
>>> x = [1,2,3]
>>> id(x)
445976
>>> mogrify(x)
>>> x
[2, 4, 6]
>>> id(x)
445976
>>> def pure(li):
... # List comprehension is consice and fun!
... return [v * 2 for v in li]
...
>>> y = pure(x)
>>> y
[4, 8, 12]
>>> id(y)
476184
>>> def mogrifyint(num):
... num = 42
...
>>> z = 5
>>> mogrifyint(z)
>>> z
5
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment