Python: Datenstrukturen und Comprehensions
125 cards · 🇺🇸 English → 🇩🇪 Deutsch
Methoden für Listen, Dictionaries und Sets sowie List-, Dict- und Generator-Comprehensions.
Study all 125 cards for free
Flashcards, quizzes, pixel-art games and a daily review that remembers for you.
Try the first 10 cards
1 / 10List.append(x)
Tap the card for the answer · swipe right if you knew it, left if not
Already have an account? Sign in
Cards
- 1List.append(x)Fügt ein Element am Ende der Liste hinzu (ähnlich wie a[len(a):] = [x])
- 2List.extend(iterable)Erweitert die Liste, indem alle Elemente des Iterables angehängt werden (ähnlich wie a[len(a):] = iterable)
- 3List.insert(i, x)Fügt ein Element an einer bestimmten Position ein (Index i). a.insert(0, x) fügt am Anfang ein, a.insert(len(a), x) entspricht append
- 4List.remove(x)Entfernt das erste Element mit dem Wert x. Löst ValueError aus, wenn kein solches Element existiert
- 5List.pop([i])Entfernt und liefert das Element an Position i. Ohne Index wird das letzte Element entfernt und zurückgegeben. Löst IndexError aus, wenn die Liste leer ist oder der Index außerhalb des gültigen Bereichs liegt
- 6List.clear()Entfernt alle Elemente aus der Liste (ähnlich wie del a[:])
- 7List.index(x[, start[, end]])Gibt den nullbasierten Index des ersten Vorkommens von x zurück. Löst ValueError aus, wenn kein solches Element existiert. Die optionalen Parameter start/end schränken die Suche ein
- 8List.count(x)Gibt an, wie oft x in der Liste vorkommt
- 9List.sort(*, key=None, reverse=False)Sortiert die Elemente der Liste in place (an Ort und Stelle)
- 10List.reverse()Kehrt die Reihenfolge der Listenelemente in place um
- 11List.copy()Gibt eine flache Kopie (shallow copy) der Liste zurück (ähnlich wie a[:])
- 12List methods like insert, remove, sortNone - sie verändern die Liste in place und geben standardmäßig None zurück (Designprinzip für alle veränderlichen Datenstrukturen in Python)
- 13Use a list as a stackVerwende append(), um oben hinzuzufügen, und pop() ohne Index, um vom oberen Ende zu entnehmen (Last-in, first-out)
- 14Why are lists not efficient as queues?Anhängen/Entfernen am Ende ist schnell, aber Einfügen/Entfernen am Anfang ist langsam (alle Elemente müssen um eins verschoben werden)
- 15What should you use instead of lists for queues?collections.deque, das schnelles Hinzufügen und Entfernen an beiden Enden ermöglicht
- 16List comprehension syntax[expression for item in iterable if condition] - erstellt eine neue Liste
- 17Equivalent of [x**2 for x in range(10)]list(map(lambda x: x**2, range(10))) oder eine for-Schleife mit append
- 18Must tuple expressions in list comprehensions be parenthesized?Ja - [(x, y) for x in range(3)] funktioniert, aber [x, y for x in range(3)] löst einen SyntaxError aus
- 19Can list comprehensions be nested?Ja - der Ausgangsausdruck kann selbst eine weitere List Comprehension sein
- 20del a[i] vs a.pop(i)del entfernt das Element; pop entfernt es und gibt es zurück
- 21Del a[:]Leert die gesamte Liste (dasselbe wie a.clear())
- 22Can del delete entire variables?Ja - del a löscht die Variable a
- 23Are tuples mutable or immutable?Unveränderlich (immutable) - einzelnen Elementen kann kein neuer Wert zugewiesen werden
- 24Can tuples contain mutable objects?Ja - z. B. ist v = ([1, 2], [3, 4]) gültig
- 25Create an empty tupleVerwende leere Klammern: ()
- 26Create a tuple with one itemSetze ein Komma nach dem Wert: ('hello',) - Klammern allein reichen nicht aus
- 27Tuple packingt = 12345, 54321, 'hello!' - die Werte werden gemeinsam in einem Tuple verpackt
- 28Sequence unpackingx, y, z = t - weist jedes Element der Sequenz einer Variable zu (erfordert gleich viele Variablen wie Elemente)
- 29Set in PythonEine ungeordnete Sammlung ohne doppelte Elemente
- 30Create an empty setVerwende set() - nicht {}, das ein leeres Dictionary erzeugt
And 95 more cards. Study the whole deck free
Articles about this deck
More Programming decks
See all- 🐍
Python: OOP Fundamentals
59 cards · 🇺🇸 English
Classes, inheritance, and core object-oriented Python concepts.
- 🐍
Python : avancé (décorateurs, lambda et exceptions)
97 cards · 🇺🇸 English
Décorateurs, fonctions lambda, gestion des exceptions et autres concepts Python avancés.
- 🐍
Python : structures de données et compréhensions
125 cards · 🇺🇸 English
Méthodes de listes/dictionnaires/ensembles ainsi que les compréhensions de listes, de dictionnaires et de générateurs.
- 🐍
Python: Fortgeschritten (Decorators, Lambda & Exceptions)
97 cards · 🇺🇸 English
Decorators, Lambda-Funktionen, Exception-Handling und weitere fortgeschrittene Python-Konzepte.
- 🐍
Python: Funciones integradas
77 cards · 🇺🇸 English
Funciones integradas esenciales que todo desarrollador Python debería conocer.
- 🐍
Python : fondamentaux de la POO
59 cards · 🇺🇸 English
Classes, héritage et concepts fondamentaux de la programmation orientée objet en Python.
