Update on the search function I posted earlier

Update on the search function I posted earlier. I have added some error checking, so if someone enters in a module name that does not exist, it tells them, and also found a flaw in the checking that I had in the code to check to make sure there was something in the search list, have replaced the use of lists with the use of deque also, it is more capable than a list. The following is the updated code:

# %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
# Search Usage example:
# searchitem = 'sin'
# modulename = 'mathutils'
# search(searchitem, modulename='bpy')
# Default search is bpy module and submodules AKA the Application modules
# Note: **search imports any modules that you search**
# 
# Searchable Standalone Modules (for the above parameter "modulename")
# aud, bgl, bl_math, blf, bmesh, bpy, bpy_extras,
# freestyle, gpu, gpu_extras, idprop, imbuf, mathutils, math
# If you enter only the searchitem, it will search the bpy module.
#
# Search Extended Usage example:
# searchitem = 'hypo'
# searchx(searchitem)
# searchx is (search extended) 
# Global search.  **imports ALL modules.**
#
# If you can't crack it, hack it!
# %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

import bpy
from collections import deque

def search(searchitem, modulename='bpy'):
    q = deque()
    if(modulename=='bpy'):
        bpyque = dir(bpy)
        bpyque.insert(0, 'bpy')
        q.append(bpyque)
        bpy_app_que = dir(bpy.app)
        bpy_app_que.insert(0, 'bpy.app')
        q.append(bpy_app_que)
        bpy_context_que = dir(bpy.context)
        bpy_context_que.insert(0, 'bpy.context')
        q.append(bpy_context_que)
        bpy_data_que = dir(bpy.data)
        bpy_data_que.insert(0, 'bpy.data')
        q.append(bpy_data_que)
        bpy_msgbus_que = dir(bpy.msgbus)
        bpy_msgbus_que.insert(0, 'bpy.msgbus')
        q.append(bpy_msgbus_que)
        bpy_ops_que = dir(bpy.ops)
        bpy_ops_que.insert(0, 'bpy.ops')
        q.append(bpy_ops_que)
        bpy_path_que = dir(bpy.path)
        bpy_path_que.insert(0, 'bpy.path')
        q.append(bpy_path_que)
        bpy_props_que = dir(bpy.props)
        bpy_props_que.insert(0, 'bpy.props')
        q.append(bpy_props_que)
        bpy_types_que = dir(bpy.types)
        bpy_types_que.insert(0, 'bpy.types')
        q.append(bpy_types_que)
        bpy_utils_que = dir(bpy.utils)
        bpy_utils_que.insert(0, 'bpy.utils')
        q.append(bpy_utils_que)
    #
    if(modulename=='mathutils'):
        import mathutils
        mathutils_que = dir(mathutils)
        mathutils_que.insert(0, 'import mathutils, mathutils')
        q.append([mathutils_que])
    #
    if(modulename=='math'):
        import math
        math_que = dir(math)
        math_que.insert(0, 'import math, math')
        q.append([math_que])
    #
    if(modulename=='aud'):
        import aud
        aud_que = dir(aud)
        aud_que.insert(0, 'import aud, aud')
        q.append([aud_que])
    #
    if(modulename=='bgl'):
        import bgl
        bgl_que = dir(bgl)
        bgl_que.insert(0, 'import bgl, bgl')
        q.append([bgl_que])
    #
    if(modulename=='bl_math'):
        import bl_math
        bl_math_que = dir(bl_math)
        bl_math_que.insert(0, 'import bl_math, bl_math')
        q.append([bl_math_que])
    #
    if(modulename=='blf'):
        import blf
        blf_que = dir(blf)
        blf_que.insert(0, 'import blf, blf')
        q.append([blf_que])
    #
    if(modulename=='bmesh'):
        import bmesh
        bmesh_que = dir(bmesh)
        bmesh_que.insert(0, 'import bmesh, bmesh')
        q.append(bmesh_que)
        bmesh_geometry_que = dir(bmesh.geometry)
        bmesh_geometry_que.insert(0, 'import bmesh, bmesh.geometry')
        q.append(bmesh_geometry_que)
        bmesh_ops_que = dir(bmesh.ops)
        bmesh_ops_que.insert(0, 'import bmesh, bmesh.ops')
        q.append(bmesh_ops_que)
        bmesh_types_que = dir(bmesh.types)
        bmesh_types_que.insert(0, 'import bmesh, bmesh.types')
        q.append(bmesh_types_que)
        bmesh_utils_que = dir(bmesh.utils)
        bmesh_utils_que.insert(0, 'import bmesh, bmesh.utils')
        q.append(bmesh_utils_que)
    #
    if(modulename=='bpy_extras'):
        import bpy_extras
        bpy_extras_que = dir(bpy_extras)
        bpy_extras_que.insert(0, 'import bpy_extras, bpy_extras')
        q.append(bpy_extras_que)
        bpy_extras_io_utils_que = dir(bpy_extras.io_utils)
        bpy_extras_io_utils_que.insert(0, 'import bpy_extras, bpy_extras.io_utils')
        q.append(bpy_extras_io_utils_que)
        bpy_extras_node_utils_que = dir(bpy_extras.node_utils)
        bpy_extras_node_utils_que.insert(0, 'import bpy_extras, bpy_extras.node_utils')
        q.append(bpy_extras_node_utils_que)
        bpy_extras_object_utils_que = dir(bpy_extras.object_utils)
        bpy_extras_object_utils_que.insert(0, 'import bpy_extras, bpy_extras.object_utils')
        q.append(bpy_extras_object_utils_que)
    #
    if(modulename=='freestyle'):
        import freestyle
        freestyle_que = dir(freestyle)
        freestyle_que.insert(0, 'import freestyle, a standalone module')
        q.append(freestyle_que)
        freestyle_chainingiterators_que = dir(freestyle.chainingiterators)
        freestyle_chainingiterators_que.insert(0, 'import freestyle, freestyle.chainingiterators')
        q.append(freestyle_chainingiterators_que)
        freestyle_functions_que = dir(freestyle.functions)
        freestyle_functions_que.insert(0, 'import freestyle, freestyle.functions')
        q.append(freestyle_functions_que)
        freestyle_predicates_que = dir(freestyle.predicates)
        freestyle_predicates_que.insert(0, 'import freestyle, freestyle.predicates')
        q.append(freestyle_predicates_que)
        freestyle_shaders_que = dir(freestyle.shaders)
        freestyle_shaders_que.insert(0, 'import freestyle, freestyle.shaders')
        q.append(freestyle_shaders_que)
        freestyle_types_que = dir(freestyle.types)
        freestyle_types_que.insert(0, 'import freestyle, freestyle.types')
        q.append(freestyle_types_que)
        freestyle_utils_que = dir(freestyle.utils)
        freestyle_utils_que.insert(0, 'import freestyle, freestyle.utils')
        q.append(freestyle_utils_que)
    #
    if(modulename=='gpu'):
        import gpu
        gpu_que = dir(gpu)
        gpu_que.insert(0, 'gpu, gpu')
        q.append(gpu_que)
        gpu_types_que = dir(gpu.types)
        gpu_types_que.insert(0, 'import gpu, gpu.types')
        q.append(gpu_types_que)
        gpu_matrix_que = dir(gpu.matrix)
        gpu_matrix_que.insert(0, 'import gpu, gpu.matrix')
        q.append(gpu_matrix_que)
        gpu_select_que = dir(gpu.select)
        gpu_select_que.insert(0, 'import gpu, gpu.select')
        q.append(gpu_select_que)
        gpu_shader_que = dir(gpu.shader)
        gpu_shader_que.insert(0, 'import gpu, gpu.shader')
        q.append(gpu_shader_que)
    #
    if(modulename=='gpu_extras'):
        import gpu_extras
        gpu_extras_que = dir(gpu_extras)
        gpu_extras_que.insert(0, 'gpu_extras, gpu_extras')
        q.append([gpu_extras_que])
    #
    if(modulename=='idprop'):
        import idprop
        idprop_types_que = dir(idprop.types)
        idprop_types_que.insert(0, 'import idprop, idprop.types')
        q.append([idprop_types_que])
    #
    if(modulename=='imbuf'):
        import imbuf
        imbuf_que = dir(imbuf)
        imbuf_que.insert(0, 'import imbuf, imbuf')
        q.append([imbuf_que])
    #
    notfound = True # For printing "Module not found." if que is empty.
    if(len(q)>0):  
        for list in q:
            for item in list:
                if searchitem.lower() == item.lower():
                    print(list[0] + "." + item)
                    notfound = False
    else:
        print('Module not found.')
    #
    if(notfound):
        print('Item not found')
        print()
        print('Searchable Standalone Modules:')
        print('aud, bgl, bl_math, blf, bmesh, bpy, bpy_extras,')
        print('freestyle, gpu, gpu_extras, idprop, imbuf, mathutils, math')



def searchx(searchitem):
    q = deque()
    import mathutils
    mathutils_list = dir(mathutils)
    mathutils_list.insert(0, 'import mathutils, mathutils')
    q.append(mathutils_list)
    #
    import math
    math_list = dir(math)
    math_list.insert(0, 'import math, math')
    q.append(math_list)
    #
    import aud
    aud_list = dir(aud)
    aud_list.insert(0, 'import aud, aud')
    q.append(aud_list)
    #
    import bgl
    bgl_list = dir(bgl)
    bgl_list.insert(0, 'import bgl, bgl')
    q.append(bgl_list)
    #
    import bl_math
    bl_math_list = dir(bl_math)
    bl_math_list.insert(0, 'import bl_math, bl_math')
    q.append(bl_math_list)
    #
    import blf
    blf_list = dir(blf)
    blf_list.insert(0, 'import blf, blf')
    q.append(blf_list)
    #
    import bmesh
    bmesh_list = dir(bmesh)
    bmesh_list.insert(0, 'import bmesh, bmesh')
    q.append(bmesh_list)
    bmesh_geometry_list = dir(bmesh.geometry)
    bmesh_geometry_list.insert(0, 'import bmesh, bmesh.geometry')
    q.append(bmesh_geometry_list)
    bmesh_ops_list = dir(bmesh.ops)
    bmesh_ops_list.insert(0, 'import bmesh, bmesh.ops')
    q.append(bmesh_ops_list)
    bmesh_types_list = dir(bmesh.types)
    bmesh_types_list.insert(0, 'import bmesh, bmesh.types')
    q.append(bmesh_types_list)
    bmesh_utils_list = dir(bmesh.utils)
    bmesh_utils_list.insert(0, 'import bmesh, bmesh.utils')
    q.append(bmesh_utils_list)
    #
    import bpy_extras
    bpy_extras_list = dir(bpy_extras)
    bpy_extras_list.insert(0, 'import bpy_extras, bpy_extras')
    q.append(bpy_extras_list)
    bpy_extras_io_utils_list = dir(bpy_extras.io_utils)
    bpy_extras_io_utils_list.insert(0, 'import bpy_extras, bpy_extras.io_utils')
    q.append(bpy_extras_io_utils_list)
    bpy_extras_node_utils_list = dir(bpy_extras.node_utils)
    bpy_extras_node_utils_list.insert(0, 'import bpy_extras, bpy_extras.node_utils')
    q.append(bpy_extras_node_utils_list)
    bpy_extras_object_utils_list = dir(bpy_extras.object_utils)
    bpy_extras_object_utils_list.insert(0, 'import bpy_extras, bpy_extras.object_utils')
    q.append(bpy_extras_object_utils_list)
    #
    import freestyle
    freestyle_list = dir(freestyle)
    freestyle_list.insert(0, 'import freestyle, a standalone module')
    q.append(freestyle_list)
    freestyle_chainingiterators_list = dir(freestyle.chainingiterators)
    freestyle_chainingiterators_list.insert(0, 'import freestyle, freestyle.chainingiterators')
    q.append(freestyle_chainingiterators_list)
    freestyle_functions_list = dir(freestyle.functions)
    freestyle_functions_list.insert(0, 'import freestyle, freestyle.functions')
    q.append(freestyle_functions_list)
    freestyle_predicates_list = dir(freestyle.predicates)
    freestyle_predicates_list.insert(0, 'import freestyle, freestyle.predicates')
    q.append(freestyle_predicates_list)
    freestyle_shaders_list = dir(freestyle.shaders)
    freestyle_shaders_list.insert(0, 'import freestyle, freestyle.shaders')
    q.append(freestyle_shaders_list)
    freestyle_types_list = dir(freestyle.types)
    freestyle_types_list.insert(0, 'import freestyle, freestyle.types')
    q.append(freestyle_types_list)
    freestyle_utils_list = dir(freestyle.utils)
    freestyle_utils_list.insert(0, 'import freestyle, freestyle.utils')
    q.append(freestyle_utils_list)
    #
    import gpu
    gpu_list = dir(gpu)
    gpu_list.insert(0, 'gpu, gpu')
    q.append(gpu_list)
    gpu_types_list = dir(gpu.types)
    gpu_types_list.insert(0, 'import gpu, gpu.types')
    q.append(gpu_types_list)
    gpu_matrix_list = dir(gpu.matrix)
    gpu_matrix_list.insert(0, 'import gpu, gpu.matrix')
    q.append(gpu_matrix_list)
    gpu_select_list = dir(gpu.select)
    gpu_select_list.insert(0, 'import gpu, gpu.select')
    q.append(gpu_select_list)
    gpu_shader_list = dir(gpu.shader)
    gpu_shader_list.insert(0, 'import gpu, gpu.shader')
    q.append(gpu_shader_list)
    #
    import gpu_extras
    gpu_extras_list = dir(gpu_extras)
    gpu_extras_list.insert(0, 'gpu_extras, gpu_extras')
    q.append(gpu_extras_list)
    #
    import idprop.types
    idprop_types_list = dir(idprop.types)
    idprop_types_list.insert(0, 'import idprop, idprop.types')
    q.append(idprop_types_list)
    #
    import imbuf
    imbuf_list = dir(imbuf)
    imbuf_list.insert(0, 'import imbuf, imbuf')
    q.append(imbuf_list)
    #
    # Assuming the user has not thoroughly searched each of the modules
    # with the normal search function:
    import bpy    
    bpylist = dir(bpy)
    bpylist.insert(0, 'bpy')
    q.append(bpylist)
    bpy_app_list = dir(bpy.app)
    bpy_app_list.insert(0, 'bpy.app')
    q.append(bpy_app_list)
    bpy_context_list = dir(bpy.context)
    bpy_context_list.insert(0, 'bpy.context')
    q.append(bpy_context_list)
    bpy_data_list = dir(bpy.data)
    bpy_data_list.insert(0, 'bpy.data')
    q.append(bpy_data_list)
    bpy_msgbus_list = dir(bpy.msgbus)
    bpy_msgbus_list.insert(0, 'bpy.msgbus')
    q.append(bpy_msgbus_list)
    bpy_ops_list = dir(bpy.ops)
    bpy_ops_list.insert(0, 'bpy.ops')
    q.append(bpy_ops_list)
    bpy_path_list = dir(bpy.path)
    bpy_path_list.insert(0, 'bpy.path')
    q.append(bpy_path_list)
    bpy_props_list = dir(bpy.props)
    bpy_props_list.insert(0, 'bpy.props')
    q.append(bpy_props_list)
    bpy_types_list = dir(bpy.types)
    bpy_types_list.insert(0, 'bpy.types')
    q.append(bpy_types_list)
    bpy_utils_list = dir(bpy.utils)
    bpy_utils_list.insert(0, 'bpy.utils')    
    q.append(bpy_utils_list)
    #
    import mathutils
    mathutils_list = dir(mathutils)
    mathutils_list.insert(0, 'import mathutils, mathutils')
    q.append(mathutils_list)
    #
    import math
    math_list = dir(math)
    math_list.insert(0, 'import math, math')
    q.append(math_list)
    #
    import aud
    aud_list = dir(aud)
    aud_list.insert(0, 'import aud, aud')
    q.append(aud_list)
    #
    import bgl
    bgl_list = dir(bgl)
    bgl_list.insert(0, 'import bgl, bgl')
    q.append(bgl_list)
    #
    import bl_math
    bl_math_list = dir(bl_math)
    bl_math_list.insert(0, 'import bl_math, bl_math')
    q.append(bl_math_list)
    #
    import blf
    blf_list = dir(blf)
    blf_list.insert(0, 'import blf, blf')
    q.append(blf_list)
    #
    import bmesh
    bmesh_list = dir(bmesh)
    bmesh_list.insert(0, 'import bmesh, bmesh')
    q.append(bmesh_list)
    bmesh_geometry_list = dir(bmesh.geometry)
    bmesh_geometry_list.insert(0, 'import bmesh, bmesh.geometry')
    q.append(bmesh_geometry_list)
    bmesh_ops_list = dir(bmesh.ops)
    bmesh_ops_list.insert(0, 'import bmesh, bmesh.ops')
    q.append(bmesh_ops_list)
    bmesh_types_list = dir(bmesh.types)
    bmesh_types_list.insert(0, 'import bmesh, bmesh.types')
    q.append(bmesh_types_list)
    bmesh_utils_list = dir(bmesh.utils)
    bmesh_utils_list.insert(0, 'import bmesh, bmesh.utils')
    q.append(bmesh_utils_list)
    #
    import bpy_extras
    bpy_extras_list = dir(bpy_extras)
    bpy_extras_list.insert(0, 'import bpy_extras, bpy_extras')
    q.append(bpy_extras_list)
    bpy_extras_io_utils_list = dir(bpy_extras.io_utils)
    bpy_extras_io_utils_list.insert(0, 'import bpy_extras, bpy_extras.io_utils')
    q.append(bpy_extras_io_utils_list)
    bpy_extras_node_utils_list = dir(bpy_extras.node_utils)
    bpy_extras_node_utils_list.insert(0, 'import bpy_extras, bpy_extras.node_utils')
    q.append(bpy_extras_node_utils_list)
    bpy_extras_object_utils_list = dir(bpy_extras.object_utils)
    bpy_extras_object_utils_list.insert(0, 'import bpy_extras, bpy_extras.object_utils')
    q.append(bpy_extras_object_utils_list)
    #
    import freestyle
    freestyle_list = dir(freestyle)
    freestyle_list.insert(0, 'import freestyle, a standalone module')
    q.append(freestyle_list)
    freestyle_chainingiterators_list = dir(freestyle.chainingiterators)
    freestyle_chainingiterators_list.insert(0, 'import freestyle, freestyle.chainingiterators')
    q.append(freestyle_chainingiterators_list)
    freestyle_functions_list = dir(freestyle.functions)
    freestyle_functions_list.insert(0, 'import freestyle, freestyle.functions')
    q.append(freestyle_functions_list)
    freestyle_predicates_list = dir(freestyle.predicates)
    freestyle_predicates_list.insert(0, 'import freestyle, freestyle.predicates')
    q.append(freestyle_predicates_list)
    freestyle_shaders_list = dir(freestyle.shaders)
    freestyle_shaders_list.insert(0, 'import freestyle, freestyle.shaders')
    q.append(freestyle_shaders_list)
    freestyle_types_list = dir(freestyle.types)
    freestyle_types_list.insert(0, 'import freestyle, freestyle.types')
    q.append(freestyle_types_list)
    freestyle_utils_list = dir(freestyle.utils)
    freestyle_utils_list.insert(0, 'import freestyle, freestyle.utils')
    q.append(freestyle_utils_list)
    #
    import gpu
    gpu_list = dir(gpu)
    gpu_list.insert(0, 'gpu, gpu')
    q.append(gpu_list)
    gpu_types_list = dir(gpu.types)
    gpu_types_list.insert(0, 'import gpu, gpu.types')
    q.append(gpu_types_list)
    gpu_matrix_list = dir(gpu.matrix)
    gpu_matrix_list.insert(0, 'import gpu, gpu.matrix')
    q.append(gpu_matrix_list)
    gpu_select_list = dir(gpu.select)
    gpu_select_list.insert(0, 'import gpu, gpu.select')
    q.append(gpu_select_list)
    gpu_shader_list = dir(gpu.shader)
    gpu_shader_list.insert(0, 'import gpu, gpu.shader')
    q.append(gpu_shader_list)
    #
    import gpu_extras
    gpu_extras_list = dir(gpu_extras)
    gpu_extras_list.insert(0, 'gpu_extras, gpu_extras')
    q.append(gpu_extras_list)
    #
    import idprop
    idprop_types_list = dir(idprop.types)
    idprop_types_list.insert(0, 'import idprop, idprop.types')
    q.append(idprop_types_list)
    #
    import imbuf
    imbuf_list = dir(imbuf)
    imbuf_list.insert(0, 'import imbuf, imbuf')
    q.append(imbuf_list)
    #    
    notfound = True
    for list in q:
        for item in list:
            if searchitem.lower() in item.lower():
                print(list[0] + "." + item)
                notfound = False
    #
    if(notfound):
        print('Item not found')