from typing import TypeVar, Generic, List from copy import copy T = TypeVar( 'T' ) class Array( Generic[ T ] ): def __init__( self, defval: T ) -> None: self.defval = copy( defval ) self.data : List[ T ] = [] def extend( self, idx: int ) -> None: while len( self.data ) <= idx: self.data.append( copy( self.defval ) ) def __setitem__( self, idx: int, val: T ) -> None: self.extend( idx ) self.data[ idx ] = val def __getitem__( self, idx: int ) -> T: self.extend( idx ) return self.data[ idx ] import run_tests