Skip to content

This is a simple implementation of ArrayList in Python, full-featured and easy to use with more than 20 methods.

License

Notifications You must be signed in to change notification settings

BaseMax/ArrayListPython

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

ArrayList Python

This is a simple implementation of ArrayList in Python, full-featured and easy to use with more than 20 methods.

Functions

  • add - Add an element to the end of the list
  • add_at - Add an element at a specific index
  • remove - Remove an element from the list
  • remove_at - Remove an element at a specific index
  • get - Get an element at a specific index
  • set - Set an element at a specific index
  • size - Get the size of the list
  • is_empty - Check if the list is empty
  • contains - Check if the list contains an element
  • index_of - Get the index of an element
  • clear - Clear the list
  • to_string - Get a string representation of the list

And a couple of magic methods:

  • __str__ - Get a string representation of the list
  • __repr__ - Get a string representation of the list
  • __len__ - Get the size of the list
  • __iter__ - Get an iterator for the list
  • __getitem__ - Get an element at a specific index
  • __setitem__ - Set an element at a specific index
  • __delitem__ - Remove an element at a specific index
  • __add__ - Add two lists together
  • __iadd__ - Add two lists together
  • __sub__ - Subtract two lists
  • __isub__ - Subtract two lists
  • __mul__ - Multiply a list by a number
  • __imul__ - Multiply a list by a number
  • __rmul__ - Multiply a list by a number
  • __eq__ - Check if two lists are equal
  • __ne__ - Check if two lists are not equal
  • __lt__ - Check if one list is less than another
  • __le__ - Check if one list is less than or equal to another
  • __gt__ - Check if one list is greater than another
  • __ge__ - Check if one list is greater than or equal to another

Usage

fromArrayListimportArrayList# Create a new listlist=ArrayList(10) # Add items to the listlist.add(1) list.add(2) list.add(3) list.add(4) list.add(5) # Print the listprint(list) # Remove an item from the listlist.remove(3) # Print the listprint(list) # Check if an item is in the listprint(list.search(3)) print(list.search(4)) # Get an item from the listprint(list.get(2)) # Print the length of the listprint(len(list)) # Print the listprint(list) # Iterate over the listforiteminlist: print("\t", item)

Output

[1, 2, 3, 4, 5] [1, 2, 4, 5] False True 4 4 [1, 2, 4, 5] 1 2 4 5

License

This project is licensed under the GPL-3.0 License - see the LICENSE file for details.

© Copyright Max Base, 2022

About

This is a simple implementation of ArrayList in Python, full-featured and easy to use with more than 20 methods.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

close