Basic nested list ip
Basic nested list ip
The indexes for the elements in a nested list are illustrated as below:
L = ['a', 'b', ['cc', 'dd', ['eee', 'fff']], 'g', 'h']
Finally, the extend() method allows you to merge one list into another.
If you know the index of the element you want to remove, the pop() method is a good
choice. This method not only removes the element at the specified index but also
returns its value.
# removed element
print(x)
# Output: cc
In cases where you don’t need the removed value, the del statement is a simple and
efficient way to delete an element by its index.
If you don’t know the exact index but know the value of the element you want to
remove, the remove() method is the way to go. This method searches the list and
removes the first occurrence of the specified value.
print(len(L)) # Output: 3
print(len(L[1])) # Output: 2