我使用list
阅读了一些快速as a reference
操作,正如here所述。
从列表中删除第一项的最快方法是什么(可能使用as a reference
和rest of list
)?
E.g:
{3,5,6,2,8}
变成
{5,6,2,8}
答案 0 :(得分:3)
这将删除列表中的第一项
set theList to rest of {3, 5, 6, 2, 8}
返回{5,6,2,8}
或者,这将删除列表中的最后一项
set theList to reverse of rest of reverse of {3, 5, 6, 2, 8}
返回{3,5,6,2}
答案 1 :(得分:0)
在您的示例列表中,{3, 5, 6, 2, 8}
,请将其设置为:
set theList to {3, 5, 6, 2, 8}
然后从列表中删除3
的一种方法是:
set theList to items 2 thru -1 of theList
或者:
set theList to items 2 thru -1 of {3, 5, 6, 2, 8}
答案 2 :(得分:0)
--use my handler
set b to {"A", 2, 3}
removeAnItemInList(1, b)
--result: {2, 3}
to removeAnItemInList(DeleteOffset, Listt)
---TH là 1 thì biến 1 thành {}
if (count Listt) is 1 and (DeleteOffset is 1) then
set Listt to {}
return Listt
end if
--- TH là 2 thì bỏ 1 hoặc 2
if (count Listt) is 2 and (DeleteOffset is 1) then
set Listt to item 2 of Listt as list
return Listt
end if
if (count Listt) is 2 and (DeleteOffset is 2) then
set Listt to item 1 of Listt as list
return Listt
end if
---TH >2 bỏ đầu cuối ----
if (count Listt) > 2 and (DeleteOffset is 1) then
set Listt to items 2 thru end of Listt
return Listt
end if
if (count Listt) > 2 and (DeleteOffset is (count Listt)) then
set Listt to items 1 thru -2 of Listt
return Listt
end if
---TH >2 bỏ giữa
if (count Listt) > 2 then
set Listt to items 1 thru (DeleteOffset - 1) of Listt & items (DeleteOffset + 1) thru end of Listt
return Listt
end if
end removeAnItemInList