Learn practical skills, build real-world projects, and advance your career
!pip install jovian --upgrade --quiet
#Do not remove the below import statement
import sys

'''This function provides the capacity, size and space left in the list.
You can invoke it to get the details of the list'''

def list_details(lst):
    #Number of elements that can be stored in the list
    print("Capacity:", (sys.getsizeof(lst)-36)//4)

    #Number of elements in the list
    print("Size:", len(lst))

    #Number of elements that can be accommodated in the space left
    print("Space Left:", ((sys.getsizeof(lst)-36) - len(lst*4))//4)

    #formula changes based on the system architecture
    #(size-36)/4 for 32 bit machines and
    #(size-64)/8 for 64 bit machines

    # 36, 64 - size of an empty list based on machine
    # 4, 8 - size of a single element in the list based on machine

sophia_lst=[]
print("Empty list created!!!")
print("List details:")
list_details(sophia_lst)
Empty list created!!! List details: Capacity: 5 Size: 0 Space Left: 5
add(element):
1. When the list is initially created, it is created with a certain capacity.
2. While adding the elements, if the list is filled to the capacity,
   a. Create a new list with increased capacity
   b. Copy the elements of initial list to the new list
3. Add the element to the end of the existing elements in the list
File "<ipython-input-3-968188fe683b>", line 1 Operation Description ^ SyntaxError: invalid syntax
#Do not remove the below import statement
import sys

'''This function provides the capacity, size and space left in the list.
You can invoke it to get the details of the list'''

def list_details(lst):
    #Number of elements that can be stored in the list
    print("Capacity:", (sys.getsizeof(lst)-36)//4)

    #Number of elements in the list
    print("Size:", len(lst))

    #Number of elements that can be accommodated in the space left
    print("Space Left:", ((sys.getsizeof(lst)-36) - len(lst*4))//4)

    #formula changes based on the system architecture
    #(size-36)/4 for 32 bit machines and
    #(size-64)/8 for 64 bit machines

    # 36,64 - size of an empty list based on machine
    # 4,8 - size of a single element in the list based on machine

sophia_lst=[]
print("Empty list created!!!")
print("List details:")
list_details(sophia_lst)


sophia_lst.append("Sugar")
print("Sophia's list after adding Sugar:")
print(sophia_lst)
print("List details:")
list_details(sophia_lst)
Empty list created!!! List details: Capacity: 5 Size: 0 Space Left: 5 Sophia's list after adding Sugar: ['Sugar'] List details: Capacity: 13 Size: 1 Space Left: 12
insert(pos, element):
 1. If the list is filled to capacity
    a. Create a new list with increased capacity
    b. Copy the elements of initial list to the new list
 2. Shift right all the existing elements from index position (pos) by 1 position
 3. Insert the element at index position (pos)