Deque

  • kolekcja zbliżona do listy
  • optymalne operacje na brzegach, nieoptymalne indeksowanie
  • implementacja bazuje na double linked liście

In [ ]:
from collections import deque
a = deque([1, 2, 3], maxlen=5)
a.append(4)
a.append(5)
a.append(6)
print(a)

Krotki

  • immutable
  • podobne do listy
  • hashowalne, listy nie są

In [ ]:
a = (1, 2, 3)
b = (1, )
c = ()
print(a, b, c)
a = tuple([1, 2, 3])
print(a)

print( (1, 2, 3)[0] )
print( (1, 'a', c)[:2] )
print( len((1, 2, 3)) )

In [ ]:
a = (1, 'a', c)
a[0] = 5

In [ ]:
a = 1, 2, 3
print(a)

a, b, c = (1, 2, 3)
print(a, b, c)

NamedTuples


In [ ]:
from collections import namedtuple
Point = namedtuple('Point', ['x', 'y'])
punkt = Point(x=5, y=10)
print(punkt)
print(punkt[0])
print(punkt[1])
print(punkt.x)
print(punkt.y)
print(punkt[:])

In [ ]:
from collections import namedtuple
Point = namedtuple('Point', ['def', 'y', 'y'], rename=False)
print( Point(1, 2, 2) )

In [ ]:
from collections import namedtuple
Point = namedtuple('Point', ['def', 'y', 'y'], rename=True)
print(Point._source)

In [ ]:
from collections import namedtuple
Point = namedtuple('Point', ['def', 'y', 'y'], rename=True)
print( Point._make([1,2,3]) )
print( Point(1, 2, 3)._asdict() ) # jakiego typu dict?
print( Point(1, 2, 3)._replace(y=5) )
print( Point._fields )