Mindmap
List Manipulation
Inhalt der Mindmap
List Manipulation
Definition
- Collection of items
- Ordered
- Mutable
- Allows duplicates
- Collection of items
Creating Lists
- Using square brackets
- Example: my_list = [1, 2, 3]
- Using the list() constructor
- Example: my_list = list((1, 2, 3))
- Using square brackets
Accessing List Elements
- Using index
- Starts at 0
- Negative indexing for reverse
- Slicing
- Subsets of lists
- Example: my_list[1:3]
- Using index
Nested Lists
- Lists within lists
- Multi-dimensional arrays
- Example: l=[12,[34,56],78,90]
- Multi-dimensional arrays
- Accessing elements
- my_list[0][1] for first sub-list
- Iterating through nested lists
- Lists within lists
List operations
- Concatenation
- Using the `+` operator
- Example: `list1 + list2`
- Using the `+` operator
- Replication
- using the multiplication operator
- syntax: list * n
- using the multiplication operator
- Slicing
- Extracting a portion of a list
- Syntax: `list[start:end:step]`
- Extracting a portion of a list
- Concatenation
Built-in function
- len()
- Function to return the number of items
- syntax: len(list_name)
- Function to return the number of items
- list()
- Creates a list in Python.
- append()
- Append an element to the end
- Syntax: list.append(item)
- Append an element to the end
- extend()
- Method to add multiple elements
- Syntax: list.extend(iterable)
- Method to add multiple elements
- insert()
- Insert an element at a specific index
- Syntax: list.insert(index, element)
- Insert an element at a specific index
- count()
- Returns the number of occurrences
- Syntax: list.count(element)
- Returns the number of occurrences
- index()
- Returns the index of an element
- Syntax: list.index(element)
- Returns the index of an element
- remove()
- Removes the first occurrence of a value
- Syntax: list.remove(value)
- Removes the first occurrence of a value
- pop()
- Removes the last item from a list Returns the item that was removed
- Can remove an item at a specific index
- Syntax: list.pop([index])
- reverse()
- Reverses the order of elements
- Syntax: list.reverse()
- Reverses the order of elements
- sort()
- Used for arranging elements
- Modifies the original list
- Syntax: list.sort()
- Used for arranging elements
- sorted()
- Sorts elements of a list
- Returns a new sorted list
- Syntax: sorted(iterable, key=None, reverse=False)
- min()
- Returns the smallest item
- Syntax: min(list)
- Returns the smallest item
- max()
- Finds the largest item
- Syntax: max(list)
- Finds the largest item
- sum()
- Adds numerical values in a list
- Syntax: sum(list)
- Adds numerical values in a list
- len()
Informationen
- Beschreibung
- Mindmap am List Manipulation, erstellt von Suja Nair am 17/05/2025.
- Erstellt von
- Suja Nair · Mai 2025
- Aktualisiert
- 17 Mai 2025
- Aufrufe
- 2
- Bewertung