Several ways...
In the layer properties dialog on the general tab you can change the name and description.
In the table of contents select the name and click again. You will be able to type anything you want.
You should also note that when in the legend if you select the layer and then the style button changing the style to layer name with label, heading with label, heading with label description. So on so forth...
To omit Legend, you have to set Legend::LayerInfos parameter which LayerInfo you want to show. As bellow,
//add the legend
dojo.connect(map,'onLayersAddResult',function(results){
var layerInfo = dojo.map(results, function(layer,index){
return {layer:layer.layer,title:layer.layer.name};
});
if(layerInfo.length > 0){
var legendDijit = new esri.dijit.Legend({
map:map,
layerInfos:layerInfo
},"legendDiv");
legendDijit.startup();
}
});
map.addLayers([waterbodies,rivers]);
This code is from ESRI's sample.
http://help.arcgis.com/en/webapi/javascript/arcgis/jssamples/widget_legend.html
This sample shows only two layers and do not show basemap Layer.
EDITED:
If you are adding DynamicMapServeLayer instead of FeatureLayer and want to control each Layers visibility inside of the MapService, you need to refresh LayerInfo with hideLayers parameter.
//show only index of 0 Layer
//layer is ArcGISDynamicMapServiceLayer object
layer.setVisibleLayers([0]);
// get legend dijit
var legendDijit = dijit.byId("legendDiv");
var visibleLayers = layer.visibleLayers;
var layerInfos = layer.layerInfos;
//create hideLayers array from layerInfos which layers are not visible
var hideLayers = [];
for (var i = 0; i < layerInfos.length; i ++) {
var layerInfo = layerInfos[i];
if(visibleLayers.indexOf(layerInfo.id) == -1){
hideLayers.push(layerInfo.id)
}
}
//refresh legend dijit with hideLayers
legendDijit.refresh([{layer:layer, hideLayers:hideLayers}]);
Best Answer
There is no need to write any additional ArcPy for this. Simply use dynamic legends (which were added at ArcGIS 10.1) when you are authoring your maps.