Hello, Regarding the [0]: this is the index number for the first item of the list. If I have a list
example_list = ["item 1","item 2","item 3","item 4"]
then example_list[0] = "item 1", and example_list[1] = "item 2". What you're seeing in your script is the creation of a list of data frame objects (all of the data frames named "Layers", as you noted) and then the index [0] which sets the df variable as the first (and most likely only) item in the list.EDIT: Here's a more succinct way to illustrate the list concept:
mxd = arcpy.mapping.MapDocument("current")
list_of_data_frames = arcpy.mapping.ListDataFrames(mxd, "Layers")
first_df = list_of_data_frames [0]
layers = arcpy.mapping.ListLayers(mxd, "*", first_df)
Again, most likely, Layers is the only data frame in the list, but even if it is a one-item list you must retrieve the data frame as a data frame, not as a one-item list of data frames.You're having trouble with the code because you are using the layer.name property (name in the TOC), and testing whether it equals the data source path for the layer, which is what you have in the list. If you use the layer.dataSource property, it should work.
for layer in layers:
if layer.dataSource in names:
layer.visible = False
(I would recommend changing the name of the list to something like "paths" instead of "names", just for clarity's sake.)Good practice for troubleshooting stuff like this is to add messages to the script output. Something like:
for layer in layers:
arcpy.AddMessage(layer) #this should be a geoprocessing layer object
arcpy.AddMessage(layer.name) #this should be the name in the TOC
arcpy.AddMessage(layer.dataSource) #this should be the path
if layer.dataSource in names:
layer.visible = False