Any way to get the some item number of a list of lists without repeat?

Say you have a list of lists of integers. without looping through every item, is there a way to get item number x of every item?

set myList to {{339, 17, 47}, {67, 17, 89}, {320, 15, 85}, {297, 18, 69}}
--> some (one-liner if possible) command for item x <--

Depending on which item, I want the result to be:
first items: {339, 267, 320, 297}
second items: {17, 17, 15, 18}
third items: {47, 89, 85, 69}
━━━━━━━━━━━━━━━━━━━━━━━━━
Model: iMac 7,1
AppleScript: AppleScript 2.2.1
Browser: Firefox 11.0
Operating System: Mac OS X (10.7)

Aesthir

it’s not possible without a loop, because a nested list of integers doesn’t consider operations on multiple references

Good timing. FWIW, ASObjC Runner (see announcement in separate thread) does this very thing:

tell application "ASObjC Runner"
	modify list {{339, 17, 47}, {67, 17, 89}, {320, 15, 85}, {297, 18, 69}} with cols to rows
	--> {{339, 67, 320, 297}, {17, 17, 15, 18}, {47, 89, 85, 69}}
end tell

I’m not sure how you’re implementing this (in terms of needing a single line here), and with the chance that I’m just stating the obvious, but, you could just write a subroutine that does this generally and call the subroutine over and over as you need it. And you may already know this, but this operation is just the transpose of a two-dimensional matrix.

I wrote a sub-routine to do this, but I need to deal with 10s, 100s, or even 1000s of lists of lists at once and the sub-routine, which consists of a repeat loop, is simply too slow. I figured it was a simple operation so there must be a way to do it faster with a single command.

Thanks jdmac and Shane, I did not recognize this until it was pointed out… but because of you two, I came up with my own solution using the “Satimage.osax” addition I already have installed:

set myArray to {{339, 17, 47}, {67, 17, 89}, {320, 15, 85}, {297, 18, 69}} as array of real
return extractarray myArray for -1 step 3 as list of integer

FWIW? Never heard that one before. “for who I’m with?” (a guess).

OmmfG! “ASObjC Runner”??? How long has this been out? and why am I just hearing about it now? (both rhetorical). Thank you, thank you, Shane! I see you are doing a lot. even wrote a book. haven’t played around too much with “ASObjC Explorer” yet because I’m still incorporating the runner’s additions into my scripts, making a lot of my old routines obsolete. Every command comes with a host of parameters, many of them interacting with each other. and with 2 interacting parameters giving much more power than the sum of each parameter’s individual power! Many of these commands blow the old saying “the whole is better than the sum of the parts” out of the water as this little motto is repeated over and over in many commands, esp. “modify list”, each doubling what you can do!

Parameter interaction is not the only commnd-buff, adding (exponentially) to power. An example is the “modify string” command’s parameter “so it is” has a huge number of enumerated values, most being powerful enough to comprise their own command (niiice!) ;). Another example is your simply adding a “false” to the beginning of a list as it is injected into your command machine and, boom! parameter negation!. wow, anyone? I’ve always wondered why the command “list files” (“Satimage.osax” again), in which the very useful parameter “not conforming to” could not be negated. Ran into this over and over and always had to find a longer, more complicated, slower way to do this.

(I don’t want to bore you guys, but I’m pretty excited at the moment.)

To top it off, it’s not up on Apple’s “AppStore”!!! (like everything else these days) Completely free?! How often is that seen lately? The temptation to make a buck for all the hard work that goes into a piece of software is generally irresistable to the majority of programmers. (of course, for a book, you’d expect that). That’s really nice to see.

btw, is there any way to change the background color in “ASObjC Explorer”? I don’t use “Smile” or “AppleScript Editor” because of this (major, imo) omission… if this option has been also neglected in the explorer, can I make a request that the option to change the background color be added in the next update? If/When this gets added (should be easy enough), inform me about it and I’ll send you a donation.

Once again, thank you Shane! :smiley:

Aesthir

FWIW - for what’s it worth?

Glad you worked it out. Unfortunately I’m still on a MacBook with MacOS 10.4, so I don’t get to explore Shane’s work. :frowning:

Sorry: for what it’s worth.

Well the version that does this has only been public for a couple of days.

Thank you. The theory behind that approach to “modify list” is to avoid having to send long lists back-and-forth as much as possible, because a lot of the time is actually spent converting from lists to Cocoa arrays and then back again. So if you can do a couple of modifications in one go, it’s a lot more efficient.

And you can send them a deeply nested list, and it will hunt through and act on all contained strings…

Hey, somebody noticed :slight_smile:

Me too :slight_smile:

I just don’t see it as something that should be sold…

I’ll add it to the wish-list.

Sorry about that. The AppleScriptObjC stuff obviously requires 10.6, so I didn’t want to ship something that only half-worked in earlier versions. And 10.6 included other changes that made it a lot easier to implement efficiently (and sometimes just plain easier).