list=['a','a','x','c','e','e','f','f','f']
i=0
count = 0
while count < len(list)-2:
if list[i] == list[i+1]:
if list [i+1] != list [i+2]:
print list[i]
i+=1
count +=1
else:print "no"
else:
i +=1
count += 1
I'm getting:
else:print "no"
^
IndentationError: unexpected indent
I'm trying to only print the elts that match the following element, but not the element following that. I'm new to Python, and I'm not sure why this isn't working.
ifandelseat the same indentation level. Also, dont uselistas a variable name, as it is a builtin typelist, since that's a defined internal function (and overriding it will cause problems).listis a built-in type and not a function; you don't override it but simply shadow the name in the scope of the variable; and it doesn't directly cause problems unless you also want to reference the type in the same scope. The actual problem with usinglistas a variable name is that it is a very indescriptive name, that it could confuse people reading the code if they don't see it is shadowed, and that it stops python and tools like pyflakes from warning you about undefined variables and also could make it harder to find bugs.