''' How do I avoid repition in for loops python ''' import itertools my_list = [1, 2, 2, 3, 4, 4, 5] for key, group in itertools.groupby(my_list): # key is the value being grouped, group is an iterator of the group # Do something with the group