<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def last_iteration(self, parameter=None):
 """Returns the iteration of the last sample of the given parameter. If parameter is ``None``, will just use the first parameter in the samples group. """

        if parameter is None:
            try:
                parameter = list(self[self.samples_group].keys())[0]
            except (IndexError, KeyError):
                # nothing has been written yet, just return 0
                return 0
        try:
            lastiter = self[self.samples_group][parameter].shape[-1]
        except KeyError:
            # no samples have been written, just return 0
            lastiter = 0
        # account for thinning
        return lastiter * self.thinned_by