<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def ends(self, layer):
 """Retrieve end positions of elements if given layer."""

        ends = []
        for data in self[layer]:
            ends.append(data[END])
        return ends