<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def AddEntry(self, thing, label=None, style=None):
 """ Add an entry to the legend. If `label` is None, `thing.GetTitle()` will be used as the label. If `style` is None, `thing.legendstyle` is used if present, otherwise `P`. """

        if isinstance(thing, HistStack):
            things = thing
        else:
            things = [thing]
        for thing in things:
            if getattr(thing, 'inlegend', True):
                thing_label = thing.GetTitle() if label is None else label
                thing_style = getattr(thing, 'legendstyle', 'P') if style is None else style
                super(Legend, self).AddEntry(thing, thing_label, thing_style)
                keepalive(self, thing)