0

I have two lists that need to matched:

List 1: Apples, Bananas, Orange, Grapes

List 2: Bananas, Pears, Kiwi, Grapes

I would like to find the matching words, but I don't even know where to start. I thought creating dictionaries would be a good way. However, I can't split it since it is a list. It would be really helpful if someone pointed me in the right direction.

Shaido
  • 27,497
  • 23
  • 70
  • 73
Jerin
  • 1
  • 1

2 Answers2

1
  • Knowing how to compare strings and output the values from your lists are the main problems that you need to solve.

  • Using for loops could be a way to check each value of your lists, and then compare each index from list 1 to list 2.

  • When you are comparing the strings, you can use the == operator to see if the strings are made up of the same characters.

I would check out these sources:

hopefully that helps, and good luck with your program!

Emma
  • 27,428
  • 11
  • 44
  • 69
0
  • Create two list
  • Iterate through the first list and compare every item in the first list to every item in the second list
  • If the items are the same, print them
list_one = ['Apples', 'Bananas', 'Orange', 'grapes']

list_two = ['Bananas', 'pears', 'Kiwi', 'grapes']

for fruit_one in list_one:
    for fruit_two in list_two:
        if fruit_one == fruit_two:
            print(fruit_one,fruit_two)
coderoftheday
  • 1,987
  • 4
  • 7
  • 21