text: """
  PyQGIS Script to Rename Layers after using Iterate feature 
  in Processing Toolbox
  
  As of QGIS 3.16, the iterate feature doesn't allow naming 
  the resulting layers based on a specific attribute. The
  resulting layers are named output_0, output_1, ...
  
  This script renames the resulting layers based on an attribute
  from the feature that was used in iteration.
  
  Here we clipped a roads layer using a districts polygon layer, 
  with the districts layer in 'Iterate' mode. If the district 
  has N features, we will get N resulting layers. This script will
  rename each layer based on the field value of the district layer.
  
  You can run the script from the Python Console Editor in QGIS.
  """
  # Prefix of the output layers generated by Iterating
  prefix = 'clipped'
  # Name of the layer which was in Iterate mode
  parent_layer_name = 'karnataka_districts'
  # Attribute from the layer to be used to fetch new layer names
  parent_layer_attr = 'DISTRICT'
  
  parent_layer = QgsProject.instance().mapLayersByName(parent_layer_name)[0]
  
  for f in parent_layer.getFeatures():
      # Layer IDs start from 1, but layer names start from 0
      layer_id = f.id()-1
      layer_name = '{}_{}'.format(prefix, layer_id)
      layer = QgsProject.instance().mapLayersByName(layer_name)[0]
      new_name = f['DISTRICT']
      layer.setName(new_name)