Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/image-processing/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在使用repeat-AppleScript时为旧列表创建新的独立(非别名)列表_Applescript - Fatal编程技术网

如何在使用repeat-AppleScript时为旧列表创建新的独立(非别名)列表

如何在使用repeat-AppleScript时为旧列表创建新的独立(非别名)列表,applescript,Applescript,我想在旧列表中选取某些元素,然后创建一个新的元素,如下所示 示例#1:获取奇数 oldList={1,2,3,4,5,6,7,8} newList={1,3,5,7} 示例2:获取字符串 oldList={1,“老虎”,{1,2,3} 新列表={“老虎”} 我为示例1编写了一个脚本: set oldList to {1, 2, 3, 4, 5, 6} set newList to {} repeat with theItem in oldList if theItem mo

我想在旧列表中选取某些元素,然后创建一个新的元素,如下所示

示例#1:获取奇数
oldList={1,2,3,4,5,6,7,8}
newList={1,3,5,7}

示例2:获取字符串
oldList={1,“老虎”,{1,2,3}
新列表={“老虎”}

我为示例1编写了一个脚本:

set oldList to {1, 2, 3, 4, 5, 6}  

set newList to {}  
repeat with theItem in oldList  
    if theItem mod 2 = 1 then  
        copy theItem to end of newList  
    end if  
end repeat
我希望新列表应该是{1,3,5},但实际上它是{oldList的第1项,oldList的第2项,oldList的第3项}。我的问题是如何解决这个问题

对于这个特定示例,一个简单的解决方案是将copy语句更改为如下内容:

copy theItem as integer to end of newList 

<>但是我在寻找一个更一般的解决方案,而不是乏味地考虑旧列表中元素的类别。谢谢!

你应该多读关于

set oldList to {1, 2, 3, 4, 5, 6}

set newList to {}
repeat with theItem in oldList
    set theItem to contents of theItem
    if theItem mod 2 = 1 then
        copy theItem to end of newList
    end if
end repeat