Skip to content

Instantly share code, notes, and snippets.

@Clivern
Created November 21, 2021 15:18
Show Gist options
  • Save Clivern/b0165e48711f518f01f68538f9aed22c to your computer and use it in GitHub Desktop.
Save Clivern/b0165e48711f518f01f68538f9aed22c to your computer and use it in GitHub Desktop.
Python 3.9.7 (default, Oct 12 2021, 22:38:23)
[Clang 13.0.0 (clang-1300.0.29.3)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>>
>>> x = [1, 2, 3, 4, 5]
>>> x.append(6)
>>> x
[1, 2, 3, 4, 5, 6]
>>> x.index(6)
5
>>> x.extend([7])
>>> x
[1, 2, 3, 4, 5, 6, 7]
>>> x.pop()
7
>>> x
[1, 2, 3, 4, 5, 6]
>>> x.len()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: 'list' object has no attribute 'len'
>>> len(x)
6
>>> x.insert(7, 7)
>>> x
[1, 2, 3, 4, 5, 6, 7]
>>> x.insert(0, 0)
>>> x
[0, 1, 2, 3, 4, 5, 6, 7]
>>> x.pop(0)
0
>>> x
[1, 2, 3, 4, 5, 6, 7]
>>> x.pop(1)
2
>>> x
[1, 3, 4, 5, 6, 7]
>>> x.clear()
>>> x
[]
>>> x = [1, 2, 3, 4, 5]
>>> x
[1, 2, 3, 4, 5]
>>> x.index(1)
0
>>> x.index(1, 1, 4)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ValueError: 1 is not in list
>>> x.reverse()
>>> x
[5, 4, 3, 2, 1]
>>> x.sort()
>>> x
[1, 2, 3, 4, 5]
>>> x
[1, 2, 3, 4, 5]
>>> x
[1, 2, 3, 4, 5]
>>>
>>> x
[1, 2, 3, 4, 5]
>>> x.count(1)
1
>>> x.count(2)
1
>>> x.append(5)
>>> x.count(5)
2
>>> x.copy((
... )
... )
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: list.copy() takes no arguments (1 given)
>>> x.copy()
[1, 2, 3, 4, 5, 5]
>>> y = x
>>> x.pop()
5
>>> x
[1, 2, 3, 4, 5]
>>> y
[1, 2, 3, 4, 5]
>>> y = x.copy()
>>> x
[1, 2, 3, 4, 5]
>>> y
[1, 2, 3, 4, 5]
>>> x.pop()
5
>>> x
[1, 2, 3, 4]
>>> y
[1, 2, 3, 4, 5]
>>> x.sort()
>>> x
[1, 2, 3, 4]
>>> x.sort(reverse=True)
>>> x
[4, 3, 2, 1]
>>> x.remove(2)
>>> x
[4, 3, 1]
>>> x.sort()
>>> x
[1, 3, 4]
>>> import bisect
>>> bisect.insort(x, 2)
>>> x
[1, 2, 3, 4]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment