InfiniteList is a data type which can support any number of elements. This can be done by using class attributes storing a low number of elements.
pip install InfiniteList
To use this library, install it using the command shown in "Installation" section. Then, read the instructions below regarding how to use operations with InfiniteList.
InfiniteList class has 'count()' method accepting an element as the parameter to get the number of occurrences of an element in the list.
For example: a: InfiniteList = InfiniteList([2, 3, 4, 3]) a.count(3) -> returns 2
InfiniteList has 'copy()' method to return a copy of itself.
InfiniteList class has 'count()' method accepting an element as the parameter to get the index of the first occurrence of that element in the list.
For example: a: InfiniteList = InfiniteList([2, 3, 4, 3]) a.index(3) -> returns 1
'reverse()' method in InfiniteList class reverses the order of elements in the list.
For example: c: InfiniteList = InfiniteList([4, 3, 5, 6]) c.reverse() print(c) -> prints [6, 5, 3, 4]
'sort()' method in InfiniteList class sorts all its elements in ascending order.
For example: c: InfiniteList = InfiniteList([4, 3, 5, 6]) c.sort() print(c) -> prints [3, 4, 5, 6]
'min()' method in InfiniteList returns the minimum element in the list.
For example: c: InfiniteList = InfiniteList([4, 3, 5, 6]) print(c.min()) -> prints 3
'max()' method in InfiniteList returns the maximum element in the list.
For example: c: InfiniteList = InfiniteList([4, 3, 5, 6]) print(c.max()) -> prints 6
'sum()' method in InfiniteList returns the sum of elements in the list.
For example: c: InfiniteList = InfiniteList([4, 3, 5, 6]) print(c.sum()) -> prints 18
InfiniteList class has 'extend()' method which adds all elements from a list or iterable to the InfiniteList. The elements are added to the end of the InfiniteList.
For example: c: InfiniteList = InfiniteList([4, 3, 5, 6]) c.extend([7, 8]) print(c) -> prints [4, 3, 5, 6, 7, 8]
'insert()' method in InfiniteList inserts an element at a particular index in the list.
For example: c: InfiniteList = InfiniteList([1, 2, 3]) c.insert(1, 4) print(c) -> prints [1, 4, 2, 3]
'append()' method in InfiniteList adds an element to the end of the list.
For example: c: InfiniteList = InfiniteList([1, 2, 3]) c.append(5) print(c) -> prints [1, 2, 3, 5]
'delete()' method in InfiniteList removes an element at a particular index in the list.
For example: c: InfiniteList = InfiniteList([4, 3, 5, 6]) c.delete(1) print(c) -> prints [4, 5, 6]
'remove()' method in InfiniteList removes an elements in the list if it exists.
For example: c: InfiniteList = InfiniteList([4, 3, 5, 6]) c.remove(5) print(c) -> prints [4, 3, 6]
'clear()' method in InfiniteList removes all elements from the list.
To get the number of elements in an InfiniteList, you can write a code in the format 'len(infinite_list)'.
For example: c: InfiniteList = InfiniteList([4, 3, 5, 6]) print(len(c)) -> prints 4
To get an item from an InfiniteList, you can write a code in the format 'infinite_list[index]'.
For example: c: InfiniteList = InfiniteList([4, 3, 5, 6]) print(c[2]) -> prints 5
To edit the value of an item in the list, you need to specify the index of the item you want to edit and the new value of the item.
For example: c: InfiniteList = InfiniteList([4, 3, 5, 6]) c[2] = 7 print(c) -> prints [4, 3, 7, 6]
Using Python's built-in 'print' function followed with an InfiniteList will print out all the elements in the InfiniteList.
For example: c: InfiniteList = InfiniteList([4, 3, 5, 6]) print(c) -> prints [4, 3, 5, 6]
The script "BigNumber_versus_mpf.py" (https://github.com/GlobalCreativeCommunityFounder/InfiniteList/blob/main/InfiniteList/InfiniteList_versus_list.py) is used to run tests of the performance of InfiniteList library against Python's built-in list class.
Examples of test results for InfiniteList versus list are in the following files:
- https://github.com/GlobalCreativeCommunityFounder/InfiniteList/blob/main/InfiniteList/InfiniteList_versus_list_append.txt (testing for performance of adding items to lists)
- https://github.com/GlobalCreativeCommunityFounder/InfiniteList/blob/main/InfiniteList/InfiniteList_versus_list_sort.txt (testing for performance of sorting items in lists)