Appending a list to a list and getting one list.
Appending a list to a list and getting one list.
- Subject: Appending a list to a list and getting one list.
- From: Paul Skinner <email@hidden>
- Date: Mon, 13 May 2002 12:40:02 -0400
From ASLG p.70-71
You can use the concatenation operator (&) to merge or add values
to lists.
For example: {"This"} & {"is", "a", "list"} --result: {"This", "is",
"a", "list"}
The concatenation operator merges the items of the two lists into
a single list, rather than making one list a value within the other
list.
For large lists, it may be more efficient to use the Copy or Set
command to insert an item directly into a list. The following script
creates a list of 10,000 integers in about a second (the required time
will vary depending on the speed of the computer used and may vary
depending on the version of AppleScript
set bigListRef to a reference to bigList
set numItems to 10000
set t to (time of (current date)) --Start timing operations.
repeat with n from 1 to numItems
copy n to the end of bigListRef
end repeat
set total to (time of (current date)) - t --End timing.
total --result: 1 second
--But...
set bigList to {}
set bigListRef to a reference to bigList
set numItems to 10000
set t to (time of (current date)) --Start timing operations.
repeat with n from 1 to numItems
set bigListRef to bigListRef & n --SuperSlowDowner!
end repeat
set total to (time of (current date)) - t --End timing.
total --result: 109 seconds
The example made me think that they are doing a similar thing
(concatenating) in the 10K iterations as they show prior to it. Not so.
If you want to concatenate a list to a list then you have to wait.
References aren't a bit of help.
Can anyone tell me how to append a list to a list and get just one
list?
With text lists under 4K text items combined I can...
set l to {"red", "orange", "yellow"}
set l2 to {"green", "blue", "indigo"}
set AppleScript's text item delimiters to "o#?o#?"--Sentinel high ascii
string
set l to every text item of ((l as text) & AppleScript's text item
delimiters & l2 as text)
-->{"red", "orange", "yellow", "green", "blue", "indigo"}
But I am hoping someone can tell me there's a better way.
--
Paul Skinner
_______________________________________________
applescript-users mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/applescript-users
Do not post admin requests to the list. They will be ignored.