blob: 2c3671c724b1135e98a32666b7d99def331270e1 [file] [log] [blame]
Leah McNuttc9c9cde2016-10-07 16:53:52 +00001*** Settings ***
2Documentation This module contains keywords for list manipulation.
3Library Collections
4
5*** Keywords ***
6Intersect Lists
7 [Documentation] Intersects the two lists passed in. Returns a list of
8 ... values common to both lists with no duplicates.
9 [Arguments] ${list1} ${list2}
10
11 # list1 The first list to intersect.
12 # list2 The second list to intersect.
13
14 ${length1}= Get Length ${list1}
15 ${length2}= Get Length ${list2}
16
17 @{intersected_list} Create List
18
19 @{larger_list}= Set Variable If ${length1} >= ${length2} ${list1}
20 ... ${length1} < ${length2} ${list2}
21 @{smaller_list}= Set Variable If ${length1} >= ${length2} ${list2}
22 ... ${length1} < ${length2} ${list1}
23
24 :FOR ${element} IN @{larger_list}
25 \ ${rc}= Run Keyword and Return Status List Should Contain Value ${smaller_list}
26 ... ${element}
27 \ Run Keyword If '${rc}' == 'True' Append to List ${intersected_list}
28 ... ${element}
29
30 @{intersected_list}= Remove Duplicates ${intersected_list}
31
Gunnar Millsc9ea9362016-12-13 16:21:13 -060032 [Return] @{intersected_list}