In [70]:
>>> a = [66.5, 33, 1, 33, 1234.5]
>>> print(a.count(33), a.count(1), a.count(34234))
>>> a.insert(1,33)
>>> a.append(33)
>>> a


2 1 0
Out[70]:
[66.5, 33, 33, 1, 33, 1234.5, 33]

In [73]:
>>> a.remove(33)
>>> a


Out[73]:
[66.5, 1, 1234.5, 33]

In [25]:
>>> a.reverse()
>>> a


Out[25]:
[66.5, 1, 33, 1234.5, 33]

In [26]:
>>> a.sort()
>>> a


Out[26]:
[1, 33, 33, 66.5, 1234.5]

In [29]:
>>> a.pop()


Out[29]:
1234.5

In [30]:
>>> a


Out[30]:
[1, 33, 66.5]

In [52]:
>>> stack = [5, 6, 7]
>>> stack.append(8)
>>> stack.append(9)
>>> stack


Out[52]:
[5, 6, 7, 8, 9]

In [33]:
>>> stack.pop()
stack


Out[33]:
[5, 6, 7]

In [45]:
>>> from collections import deque
>>> quene = deque(['Eric', 'Peter', 'John'])
>>> quene.append('Geoge')
>>> quene.append('Allen')
>>> quene.popleft()
>>> quene.popleft()
>>> quene


Out[45]:
deque(['John', 'Geoge', 'Allen'])

In [78]:
>>> square = []
>>> for x in range(10):
...     square.append(x**2)
>>> square


Out[78]:
[0, 1, 4, 9, 16, 25, 36, 49, 64, 81]

In [80]:
>>> squares = list(map(lambda x: x**2, range(10)))
>>> squares


Out[80]:
[0, 1, 4, 9, 16, 25, 36, 49, 64, 81]

In [82]:
>>> squares = [x**2 for x in range(10)]
>>> squares


Out[82]:
[0, 1, 4, 9, 16, 25, 36, 49, 64, 81]

In [84]:
>>> [(x,y) for x in [1,2,3] for y in [3,1,4] if x != y]


Out[84]:
[(1, 3), (1, 4), (2, 3), (2, 1), (2, 4), (3, 1), (3, 4)]

In [91]:
>>> combs = []
>>> for x in [1,2,3]:
...    for y in [3,1,4]:
...         if x != y:
...             combs.append((x,y))
>>> combs


Out[91]:
[(1, 3), (1, 4), (2, 3), (2, 1), (2, 4), (3, 1), (3, 4)]

In [92]:
>>> vec = [-4, -2, 0, 2, 4]
>>> [x*2 for x in vec]


Out[92]:
[-8, -4, 0, 4, 8]

In [93]:
>>> [x for x in vec if x >0]


Out[93]:
[2, 4]

In [94]:
>>> [abs(x) for x in vec]


Out[94]:
[4, 2, 0, 2, 4]

In [96]:
>>> freshfruit = ['Banana','Apple','Passionfruit']
>>> [weapon.strip() for weapon in freshfruit]


Out[96]:
['Banana', 'Apple', 'Passionfruit']

In [97]:
>>> [(x, x**2) for x in range(6)]


Out[97]:
[(0, 0), (1, 1), (2, 4), (3, 9), (4, 16), (5, 25)]

In [98]:
>>> vec = [[1,2,3],[4,5,6],[7,8,9]]
>>> [num for elem in vec for num in elem]


Out[98]:
[1, 2, 3, 4, 5, 6, 7, 8, 9]

In [100]:
>>> from math import pi
>>> [str(round(pi,i)) for i in range(1,6)]


Out[100]:
['3.1', '3.14', '3.142', '3.1416', '3.14159']

In [102]:
>>> matrix = [
    [1,2,3,4],
    [5,6,7,8],
    [9,10,11,12]
    ]
>>> matrix


Out[102]:
[[1, 2, 3, 4], [5, 6, 7, 8], [9, 10, 11, 12]]

In [106]:
>>> [[row[i] for row in matrix] for i in range(4)]


Out[106]:
[[1, 5, 9], [2, 6, 10], [3, 7, 11], [4, 8, 12]]

In [114]:
>>> transposed = []
>>> for i in range(4):
        transposed.append([row[i] for row in matrix])
>>> transposed


Out[114]:
[[1, 5, 9], [2, 6, 10], [3, 7, 11], [4, 8, 12]]

In [117]:
>>> transposed = []
>>> for i in range(4):
        transposed_row = []
        for row in matrix:
            transposed_row.append(row[i])
        transposed.append(transposed_row)
>>> transposed


Out[117]:
[[1, 5, 9], [2, 6, 10], [3, 7, 11], [4, 8, 12]]

In [118]:
>>> list(zip(*matrix))


Out[118]:
[(1, 5, 9), (2, 6, 10), (3, 7, 11), (4, 8, 12)]

In [123]:
>>> a = [-1,0,1,5,8.33,123]
>>> del a[0]
>>> a
>>> del a[2:4]
>>> a
>>> del a[:]
>>> a


Out[123]:
[]

In [124]:
>>> a = [1,2,3,4,5,6,]
>>> del a


---------------------------------------------------------------------------
NameError                                 Traceback (most recent call last)
<ipython-input-124-1ce04bd8e36d> in <module>()
      1 a = [1,2,3,4,5,6,]
      2 del a
----> 3 a

NameError: name 'a' is not defined

In [125]:
>>> t = 1234, 5432, 'hello!'
>>> t[0]


Out[125]:
1234

In [126]:
>>> t


Out[126]:
(1234, 5432, 'hello!')

In [127]:
>>> u = t, (1,2,3,4,5)
>>> u


Out[127]:
((1234, 5432, 'hello!'), (1, 2, 3, 4, 5))

In [128]:
>>> u[0] = 888


---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-128-bac509fe13de> in <module>()
----> 1 u[0] = 888

TypeError: 'tuple' object does not support item assignment

In [129]:
>>> basket = ['Apple','Banana','Pinapple','flower','orange']
>>> basket


Out[129]:
['Apple', 'Banana', 'Pinapple', 'flower', 'orange']

In [130]:
>>> 'orange' in basket


Out[130]:
True

In [131]:
>>> 'hello' in basket


Out[131]:
False

In [132]:
>>> a = set('abcdefghijk')
>>> b = set('abcdabc')
>>> a


Out[132]:
{'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k'}

In [133]:
>>> b


Out[133]:
{'a', 'b', 'c', 'd'}

In [134]:
>>> a | b


Out[134]:
{'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k'}

In [135]:
>>> a & b


Out[135]:
{'a', 'b', 'c', 'd'}

In [136]:
>>> a ^ b


Out[136]:
{'e', 'f', 'g', 'h', 'i', 'j', 'k'}