Find values in common between two arrays

后端 未结 3 1667
北海茫月
北海茫月 2021-01-30 10:52

If I want to compare two arrays and create an interpolated output string if an array variable from array y exists in x how can I get an output for each

3条回答
  •  礼貌的吻别
    2021-01-30 11:07

    You can use the set intersection method & for that:

    x = [1, 2, 4]
    y = [5, 2, 4]
    x & y # => [2, 4]
    

提交回复
热议问题