Python: Check whether two lists are circularly identical
Check Circularly Identical Lists
Write a Python program to check whether two lists are circularly identical.
Visual Presentation
Sample Solution:
Python Code:
# Define three lists: list1, list2, and list3, each containing a sequence of numbers
list1 = [10, 10, 0, 0, 10]
list2 = [10, 10, 10, 0, 0]
list3 = [1, 10, 10, 0, 0]
# Compare list1 and list2
print('Compare list1 and list2')
# Check if the string representation of list2 is present in the string representation of list1 repeated twice
# The result will be True if list2 is a subsequence of list1 repeated twice, otherwise False
print(' '.join(map(str, list2)) in ' '.join(map(str, list1 * 2)))
# Compare list1 and list3
print('Compare list1 and list3')
# Check if the string representation of list3 is present in the string representation of list1 repeated twice
# The result will be True if list3 is a subsequence of list1 repeated twice, otherwise False
print(' '.join(map(str, list3)) in ' '.join(map(str, list1 * 2)))
Sample Output:
Compare list1 and list2 True Compare list1 and list3 False
Flowchart:
Python Code Editor:
Previous: Write a Python program to select an item randomly from a list.
Next: Write a Python program to find the second smallest number in a list.
What is the difficulty level of this exercise?
Test your Programming skills with w3resource's quiz.
- Weekly Trends and Language Statistics
- Weekly Trends and Language Statistics