2014-07-03 65 views
0

所以我有話名單:AppleScript的:用一個列表來清除另一個列表

{{"YOU"}, {"KNOW"}, {"BETTER"}, {"THAN"}, {"TO"}, {"PARK"}, {"YOUR"}, {"CAR"}, {"IN"}, {"UNASSIGNED"}, {"SPOTS"}} 

,我也有這樣的名單:

{{"0", "<SIL>"}, {"269", "YOU"}, {"389", "<SIL>"}, {"439", "KNOW"}, {"509", "BETTER"}, {"829", "THAN"}, {"969", "TO"}, {"1059", "PARK"}, {"1350", "YOUR"}, {"1449", "CAR"}, {"1839", "IN"}, {"2059", "<SIL>"}, {"2089", "UNASSIGNED"}, {"2659", "SPOTS"}} 

我想淘汰所有多餘的子列表(不包含第一個列表中的單詞)留下如下內容:

{{"269", "YOU"}, {"439", "KNOW"}, {"509", "BETTER"}, {"829", "THAN"}, {"969", "TO"}, {"1059", "PARK"}, {"1350", "YOUR"}, {"1449", "CAR"}, {"1839", "IN"}, {"2089", "UNASSIGNED"}, {"2659", "SPOTS"}} 

我是新的以applescript所以這對我來說真的很難。

任何幫助將不勝感激!

+0

歡迎使用計算器。這是一個用戶在遇到絆腳石時需要編寫代碼的幫助,並需要幫助解決問題的網站。因此,預計您會發現您正在編寫代碼而不是尋找某人爲您編寫代碼。請告訴我們你的代碼卡在哪裏,我們將非常樂意協助 – mcgrailm

+0

對不起,如果我不應該幫助他,mcgrailm。我看到他已經正確地形成了蘋果列表,所以他認爲他已經開始了。原諒。 – jweaks

+0

不需要道歉:)快樂,你可以幫助他出 – mcgrailm

回答

2

該腳本每次循環顯示一個列表對,並且對於每個列表對,都檢查原始列表中的每個單詞以查看它是否在該對中,如果是,則將該對添加到結果列表中。

set L1 to {{"YOU"}, {"KNOW"}, {"BETTER"}, {"THAN"}, {"TO"}, {"PARK"}, {"YOUR"}, {"CAR"}, {"IN"}, {"UNASSIGNED"}, {"SPOTS"}} 

set L2 to {{"0", "<SIL>"}, {"269", "YOU"}, {"389", "<SIL>"}, {"439", "KNOW"}, {"509", "BETTER"}, {"829", "THAN"}, {"969", "TO"}, {"1059", "PARK"}, {"1350", "YOUR"}, {"1449", "CAR"}, {"1839", "IN"}, {"2059", "<SIL>"}, {"2089", "UNASSIGNED"}, {"2659", "SPOTS"}} 

set L3 to {} -- initiate the resulting list 
repeat with wordPair in L2 -- cycle through each list pair in L2 
    repeat with wordSingle in L1 -- check each source word to see if found in the list pair 
     if wordSingle is in wordPair then 
      copy (wordPair as list) to end of L3 
      exit repeat 
     end if 
    end repeat 
end repeat 
return L3 
+0

謝謝!我知道這是類似的東西,但不能得到語法。 – user3803526