Skip to content
Advertisement

How do I print the overlap value from two lists by trimming the first 3 letters using Python 3

My goal is using Python 3 to check if there are any top 3 letters that overlap between List_A and List_B, and print the overlap data from List_B.

JavaScript

The following is the for loop of printing the overlap data between List_A and List_B.

JavaScript

The output is

JavaScript

Next, I try to select the first 3 letters and append them in the new List of A and B, then compare if there is any overlap.

JavaScript

the output is

JavaScript

However, my expected output is the original data in List_B, such as:

JavaScript

May I ask how could I modify the code?

Advertisement

Answer

The code was printing the elements in 3-letters list. You might first get its index and print the overlapped with same index in original list.

JavaScript
User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement