Last active
September 23, 2015 17:47
-
-
Save simeonwillbanks/592850 to your computer and use it in GitHub Desktop.
#Python mogrify
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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