Write a python program to check whether two lists are circularlyidentical

Python | Check whether two lists are circularly identical

Given two lists, check if they are circularly identical or not.

Examples:

Input : list1 = [10, 10, 0, 0, 10] list2 = [10, 10, 10, 0, 0] Output : Yes Explanation: yes they are circularly identical as when we write the list1 last index to second last index, then we find it is circularly same with list1 Input : list1 = [10, 10, 10, 0, 0] list2 = [1, 10, 10, 0, 0] Output :No

Python: Check whether two lists are circularly identical

Last update on October 08 2020 09:22:33 (UTC/GMT +8 hours)

Python | Checking whether two Lists are Circularly Identical

Posted in Programming LAST UPDATED: SEPTEMBER 27, 2021

In this tutorial, we will understand how to identify if two lists are circularly identical. But first, let's understand what does it mean, being circularly identical? Let us take an example, below we have some sample input and output.

Sample input: [1, 2, 1, 1, 3] and [3, 1, 2, 1, 1]

Sample output: Yes

Sample input: [3, 1, 2, 1, 1] and [2, 1, 1, 2, 1]

Sample output: No

It can be seen that circularly identical refers to two lists that can be obtained from each other if one or more of the elements in the list are rotated/displaced from their original index and placed at the beginning. For example: the list [1,2,1,1,3] element at index 4, i.e the element 3 can be placed at the 0th index. This would give list [3,1,2,1,1]. The elements are merely rotated, the other values order in the list is not lost.

Python program to check whether two lists are circularly identical

PythonServer Side ProgrammingProgramming

Here two lists are given. Our task is to check and found weather two given lists are circularly identical or not.

(Python Example for Citizen Data Scientist & Business Analyst)

Write a python program to check whether two lists are circularly identical.

Sample Solution

Python Code:

list1 = [10, 10, 0, 0, 10] list2 = [10, 10, 10, 0, 0] list3 = [1, 10, 10, 0, 0] print('Compare list1 and list2') print(' '.join(map(str, list2)) in ' '.join(map(str, list1 * 2))) print('Compare list1 and list3') print(' '.join(map(str, list3)) in ' '.join(map(str, list1 * 2)))

Sample Output:

Compare list1 and list2 True Compare list1 and list3 False

Video liên quan

Postingan terbaru

LIHAT SEMUA