0

2つのリストがあります。最初のリストに含まれている要素を2番目のリストに追加する必要があります。2番目のリストに最初のリストの要素の一部が含まれている場合、それらは2番目のリストに追加されるべきではありません(繰り返しを避けるため)。

現在使用しているもの:

set ListB to ListB & ListA

しかし、明らかにこれらは重複を考慮していません。

4

2 に答える 2

2

adayzdoneサンプルコードのように、リストに文字列のみが含まれ、改行が含まれていない場合、両方のリストに数千のアイテムが含まれていると、より高速な方法を使用できます。

--NOTE: Only works with lists containing strings and not containing linefeeds. 
set listA to {"A1", "A2", "A3"}
set listB to {"B1", "B2", "A3"}

set AppleScript's text item delimiters to linefeed
set newList to every paragraph of (do shell script "sort -fu <<< " & quoted form of ((listA as string) & linefeed & listB as string))
set AppleScript's text item delimiters to ""

return newList
于 2012-11-12T15:52:53.953 に答える
1

試す:

set listA to {"A1", "A2", "A3"}
set listB to {"B1", "B2", "A3"}

repeat with anItem in listB
    if anItem is not in listA then
        set end of listA to contents of anItem
    end if
end repeat

return listA
于 2012-11-11T15:25:27.000 に答える