[....]
[1234]
[1234....]
In [ ]:
liczby = [1, 2, 3, 4, 5]
print(liczby)
print(list(range(5)))
print(len([1, 2, 3, 4, 5]))
In [ ]:
from functools import partial
padding = partial('{0:{fill}{align}16}'.format, fill=" ", align="^")
a = [1, 2, 3, 4]
print(padding("copy:"), a[:])
print(padding("last item:"), a[-1])
print(padding("slice:"), a[0:2])
print(padding("reversed:"), a[::-1])
In [ ]:
from functools import partial
padding = partial('{0:{fill}{align}16}'.format, fill=" ", align="^")
a = [1, 2, 3, 4, 4]
a.append(5)
print(padding("append:"), a)
print(padding("count:"), a.count(4))
a.extend([5, 5])
print(padding("extend:"), a)
a.reverse()
print(padding("reversed: "), a)
a = a + [5, 5]
print(padding("addition: "), a)
In [ ]:
from functools import partial
padding = partial('{0:{fill}{align}16}'.format, fill=" ", align="^")
a = [5, 6, 7, 1, 1, 3, 4]
a.sort()
print(padding("sorted:"), a)
a.remove(6)
print(padding("remove:"), a)
print(padding("popping return:"), a.pop())
print(padding("after pop:"), a)
a.insert(0, 5)
print(padding("insert at 0:"), a)
a.insert(2, 5)
print(padding("insert at 2:"), a)
In [ ]:
liczby = [1, 2, 3, 4, 5]
srodek = slice(1, -1)
print(liczby[srodek])
liczby = list(range(20))
parzyste = slice(0, len(liczby), 2)
print(liczby[parzyste])
In [ ]:
b = 0
print([b]*3)
In [ ]:
b = []
a = [b] * 3
b.append(1)
print(a)
a = [[]] * 3
a[0].append(1)
print(a)
In [ ]:
a = [4] * 3
a[0] = 5
print(a)
In [ ]:
liczby = [1,2,3]
liczby.append(liczby)
print(liczby)
print(liczby[-1])