Social Sciences, asked by NAVA98, 5 months ago

To compare two arrays, we can use
a) Comparison operator ‘==’ directly on arrays
b) “switch case” statement
c) “for” loop
d) ternary operator on arrays

Answers

Answered by reenarani312
0

Answer:

"for" loop is the answer

Answered by qwmillwall
0

Option (c) "for" loop is the correct answer.

  • We can use a for loop to compare the given two arrays.
  • Iterate in both of the arrays and compare if one element is present in the second array.

Example code (Python3):

list1 = [1, 2, 3, 4, 5]\\list2 = [1, 2, 3, 7, 8]\\result = [ ]\\for\hspace{3}item\hspace{3}in\hspace{3}list1:\\\phantom{30}for\hspace{3}item1\hspace{3}in\hspace{3}list2:\\\phantom{1000}if\hspace{3}item == item1:\\\phantom{500000}result.append(item)\\print(result)

Output:

[1,2,3]

#SPJ3

Similar questions