list1 = ['a', 'a', 'a', 'b', 'b' , 'a', 'f', 'c', 'a','a']
temp_list = []
for item in list1:
if len(temp_list) == 0:
temp_list.append(item)
elif len(temp_list) > 0:
if temp_list[-1] != item:
temp_list.append(item)
print(temp_list)
- Fetch each item from the main list(list1).
- If the 'temp_list' is empty add that item.
- If not , check whether the last item in the temp_list is
not same as the item we fetched from 'list1'.
- if items are different append into temp_list.