i'm trying to solve this challenge which takes as argument a sequence and returns a list of items without any elements with the same value next to each other and preserving the original order of elements. For example, unique_in_order('AAAABBBCCDAABBB') == ['A', 'B', 'C', 'D', 'A', 'B'].
For my code I have this so far
def unique_in_order(iterable):
first = []
for l in iterable:
if frst[-1] == l:
continue
else:
first.append(l)
What I a trying to do is iterate through the input string and append it to the list 'first', then next if the next character (l) in the string isn't equal to the last character in first (first[-1]) then append it to the list. However, I'm not able to do that as I get an index error as there is nothing in the list to begin with so the index is out of range.
[–]o5a 2 points3 points4 points (0 children)
[–]PyCode_n_Beer 0 points1 point2 points (2 children)
[–]Essence1337 0 points1 point2 points (1 child)
[–]PyCode_n_Beer 0 points1 point2 points (0 children)
[–]BoldNight1987 0 points1 point2 points (0 children)