Other than just doing a for loop you could use itertools groupby:
import itertools
a = [5,5,5,5,3,3,2,2,2,2,5,5,5,2,2,2,2,2]
b = [x[0] for x in itertools.groupby(a)] # [5, 3, 2, 5, 2]
Documentation for this can be found here: https://docs.python.org/3/library/itertools.html#itertools.groupby
EDIT: Some clarification. The reason this is able to count re-occurrences in the list is explained by this paragraph in the documentation (emphasis mine):
The operation of groupby() is similar to the uniq filter in Unix. It
generates a break or new group every time the value of the key
function changes [...]