This is a simple implementation of ArrayList in Python.
add
- Add an element to the end of the listadd_at
- Add an element at a specific indexremove
- Remove an element from the listremove_at
- Remove an element at a specific indexget
- Get an element at a specific indexset
- Set an element at a specific indexsize
- Get the size of the listis_empty
- Check if the list is emptycontains
- Check if the list contains an elementindex_of
- Get the index of an elementclear
- Clear the listto_string
- Get a string representation of the list
from ArrayList import ArrayList
# Create a new list
list
6B5E
= ArrayList(10)
# Add items to the list
list.insert(1)
list.insert(2)
list.insert(3)
list.insert(4)
list.insert(5)
# Print the list
print(list)
# Remove an item from the list
list.remove(3)
# Print the list
print(list)
# Check if an item is in the list
print(list.search(3))
print(list.search(4))
# Get an item from the list
print(list.get(2))
# Print the length of the list
print(len(list))
# Print the list
print(list)
# Iterate over the list
for item in list:
print("\t", item)
[1, 2, 3, 4, 5]
[1, 2, 4, 5]
False
True
4
4
[1, 2, 4, 5]
1
2
4
5
This project is licensed under the GPL-3.0 License - see the LICENSE file for details.
© Copyright Max Base, 2022