Skip to content

Instantly share code, notes, and snippets.

@casperlehmann
Created October 17, 2019 20:41
Show Gist options
  • Save casperlehmann/ae398d915467e76e8e45e65aa6e6c229 to your computer and use it in GitHub Desktop.
Save casperlehmann/ae398d915467e76e8e45e65aa6e6c229 to your computer and use it in GitHub Desktop.
I feel like this shouldn't be allowed
# weirdness.py
def loop_for(i, li=[]):
while len(li) <= i:
print(li)
li[len(li):len(li)+1] = [len(li)]
loop_for(9)
loop_for(9, ['x', 'y', 'z'])
"""
[]
[0]
[0, 1]
[0, 1, 2]
[0, 1, 2, 3]
[0, 1, 2, 3, 4]
[0, 1, 2, 3, 4, 5]
[0, 1, 2, 3, 4, 5, 6]
[0, 1, 2, 3, 4, 5, 6, 7]
[0, 1, 2, 3, 4, 5, 6, 7, 8]
['x', 'y', 'z']
['x', 'y', 'z', 3]
['x', 'y', 'z', 3, 4]
['x', 'y', 'z', 3, 4, 5]
['x', 'y', 'z', 3, 4, 5, 6]
['x', 'y', 'z', 3, 4, 5, 6, 7]
['x', 'y', 'z', 3, 4, 5, 6, 7, 8]
"""
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment