Skip to content

Instantly share code, notes, and snippets.

@bekatom
Created August 4, 2015 13:49
Show Gist options
  • Select an option

  • Save bekatom/f23acd2f0a9398fa046a to your computer and use it in GitHub Desktop.

Select an option

Save bekatom/f23acd2f0a9398fa046a to your computer and use it in GitHub Desktop.
Mutable list problems
# 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