1*** 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
32    [Return]  @{intersected_list}
33