PyPython
BeginnerLesson 6 of 12

Lists, Tuples, Dictionaries, Sets – Python

The four most important collection types.

List (mutable, ordered), tuple (immutable), dictionary (key → value), set (unique values).

zahlen = [3, 1, 2]
zahlen.append(5)
zahlen.sort()
print(zahlen, zahlen[0], zahlen[-1], zahlen[1:3])

punkt = (4, 7)            # tuple
person = {"name": "Ada", "alter": 36}
person["stadt"] = "London"
print(person.get("email", "none"))

einzigartig = set([1, 2, 2, 3, 3])
print(einzigartig)        # {1, 2, 3}

List comprehensions create lists compactly:

quadrate = [x**2 for x in range(6)]
gerade = [x for x in range(10) if x % 2 == 0]
laengen = {w: len(w) for w in ["Python", "Go", "C"]}
print(quadrate, gerade, laengen)