Created
August 4, 2015 13:49
-
-
Save bekatom/f23acd2f0a9398fa046a to your computer and use it in GitHub Desktop.
Mutable list problems
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
| # first version | |
| def boo1(l=[]): | |
| l = list(l) | |
| l.append(1) | |
| return l | |
| # second version | |
| def boo2(l=[]): | |
| result = [] | |
| result.extend(l) | |
| result.append(1) | |
| return result | |
| m = [1, 2, 3, 4] | |
| print boo1(m) | |
| print boo1(m) | |
| print boo1(m) | |
| print boo1(m) | |
| print boo2(m) | |
| print boo2(m) | |
| print boo2() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment