def delete_mapfile_layer(mapfile, layerName):
    mapfile.seek(0)
    endTagCount = None
    bytePosition = 0
    layerFound = False
    for line in mapfile.readlines():
        # Record byte position of LAYER tag in case we're about to find that it's a dupe
        if 'layer' in line.lower():
            layerStart = bytePosition
        # If this is a duplicate tag, start counting END tags
        if all(tag in line.lower() for tag in ('name',identifier)):
            endTagCount = 1
        # Increment the END count if additional tags that require an END appear
        if endTagCount > 0 and any(keyword in line.lower() for keyword in ('validation','projection','metadata')):
            endTagCount += 1
        # Decrement the END count each time an END tag is found
        if endTagCount > 0 and "end" in line.lower():
            endTagCount -= 1
        # Increment the overall file position
        bytePosition += len(line)
        # When last END tag is found, record the position of the final line and push LAYER start and end positions to list
        if endTagCount == 0:
            mapfile.seek(bytePosition)
            remainder = mapfile.read()
            mapfile.seek(layerStart)
            mapfile.truncate()
            mapfile.write(remainder)
            layerFound = True
            break
    return layerFound
iterator doing a breadth first expansion of args
dataset/ETHPy150Open nasa-gibs/onearth/src/layer_config/bin/oe_configure_layer.py/delete_mapfile_layer--crossover with--dataset/ETHPy150Open CountZer0/PipelineConstructionSet/python/maya/site-packages/pymel-1.0.3/pymel/util/arguments.py/breadthIterArgs