Looking to add a legends using arcpy

Discussion created by swati2958 on Jan 11, 2014
Latest reply on Nov 20, 2017 by CarrierAD

I am trying to add a legend to a map layout using arcpy. after going through the tutorials I have used the following code :
import arcpy
mxd = arcpy.mapping.MapDocument(r"C:\Project\Project.mxd")
df = arcpy.mapping.ListDataFrames(mxd)[0]
lyrFile = arcpy.mapping.Layer(r"C:\Project\Data\Rivers.lyr")
arcpy.mapping.AddLayer(df, lyrFile, "TOP")
styleItem = arcpy.mapping.ListStyleItems("USER_STYLE", "Legend Items", "NewDefaultLegendStyle")[0]
legend = arcpy.mapping.ListLayoutElements(mxd, "LEGEND_ELEMENT")[0]
legend.updateItem(lyrFile, styleItem)
del mxd

but everytime I run this code I found an error :

Runtime error
Traceback (most recent call last):
  File "<string>", line 1, in <module>
AttributeError: 'list' object has no attribute 'updateItem'

Kindly help to resolve this.
I am new to map automation and using Python.