Skip to content

Instantly share code, notes, and snippets.

@casperlehmann
Created October 17, 2019 20:41
Show Gist options
  • Select an option

  • Save casperlehmann/ae398d915467e76e8e45e65aa6e6c229 to your computer and use it in GitHub Desktop.

Select an option

Save casperlehmann/ae398d915467e76e8e45e65aa6e6c229 to your computer and use it in GitHub Desktop.

Revisions

  1. casperlehmann created this gist Oct 17, 2019.
    28 changes: 28 additions & 0 deletions weirdness.py
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,28 @@
    # 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]
    """