I have lists like this, and I want to know if their elements are alternating. For example:
list1 = ['A', 'C', 'A', 'C', 'A', 'C'] # result = True
list2 = ['A', 'A', 'A', 'C', 'A', 'C'] # result = False
list3 = ['A', 'C', 'C', 'C', 'A', 'C'] # result = False
list4 = ['A', 'C', 'A', 'C', 'A', 'A'] # result = False
- Elements of the list will always be a string.
- The length of this string is not fixed.
- The list will always contain only two distinct values.
Now, How to check if elements of list are alternating in Python?