• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Flattening a list
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Flattening a list


  • Subject: Flattening a list
  • From: Michelle Steiner <email@hidden>
  • Date: Sat, 15 May 2004 18:21:45 -0700

Usually, when concatenating items to the end of a list, it's better to use copy rather than set. However, when trying to flatten a list, you have to use set.

set variable to "zzz"
set a to {{1, "z", 3}, {variable, "b", "c"}, {5, "text", variable}}
set b to {}
repeat with i from 1 to count of a
copy item i of a to end of b
end repeat
b

--> {{1, "z", 3}, {"zzz", "b", "c"}, {5, "text", "zzz"}}

set variable to "zzz"
set a to {{1, "z", 3}, {variable, "b", "c"}, {5, "text", variable}}
set b to {}
repeat with i from 1 to count of a
set b to b & item i of a
end repeat
b

--> {1, "z", 3, "zzz", "b", "c", 5, "text", "zzz"}

Is there a better way to flatten a list than looping like this?

-- Michelle

--
If you're not going somewhere, you're not getting anywhere.
_______________________________________________
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.


  • Follow-Ups:
    • Re: Flattening a list
      • From: Paul Berkowitz <email@hidden>
    • Re: Flattening a list
      • From: Joseph Weaks <email@hidden>
  • Prev by Date: Remote events conundrum
  • Next by Date: Re: Flattening a list
  • Previous by thread: Remote events conundrum
  • Next by thread: Re: Flattening a list
  • Index(es):
    • Date
    • Thread