Python: List integers containing exactly three distinct values, such that no integer repeats twice consecutively
Four Distinct Values Non-Consecutive
Write a Python program to find a list of integers containing exactly four distinct values, such that no integer repeats twice consecutively among the first twenty entries.
Note: The list needs to have length greater than ten.)
Input: [1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4] Output: True Input: [1, 2, 3, 3, 1, 2, 3, 3, 1, 2, 3, 3, 1, 2, 3, 3] Output: False Input: [1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3] Output: False
Visual Presentation:



Sample Solution:
Python Code:
Sample Output:
Original list: [1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4] Check said list of integers containing exactly four distinct values, such that no integer repeats twice consecutively: True Original list: [1, 2, 3, 3, 1, 2, 3, 3, 1, 2, 3, 3, 1, 2, 3, 3] Check said list of integers containing exactly four distinct values, such that no integer repeats twice consecutively: False Original list: [1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3] Check said list of integers containing exactly four distinct values, such that no integer repeats twice consecutively: False
Flowchart:

For more Practice: Solve these Related Problems:
- Write a Python program to verify that a list contains exactly four distinct values and that no value is repeated consecutively.
- Write a Python program to count unique elements in a list and check that none appear twice in a row within the first twenty entries.
- Write a Python program to iterate over a list and ensure it has exactly four unique numbers and that no adjacent pair are identical.
- Write a Python program to use slicing and set operations to confirm that the first twenty elements of a list have four distinct values with no consecutive duplicates.
Go to:
Previous: Split a string of words separated by commas and spaces into 2 lists: words and separators.
Next: Separate Parentheses Groups Perfectly.
Python Code Editor :
Have another way to solve this solution? Contribute your code (and comments) through Disqus.
What is the difficulty level of this exercise?
Based on 136 votes, average difficulty level of this exercise is Hard
.
Test your Programming skills with w3resource's quiz.