• 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
Re: getting duplicates in a list by item id
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: getting duplicates in a list by item id


  • Subject: Re: getting duplicates in a list by item id
  • From: Philip Aker <email@hidden>
  • Date: Sun, 26 Aug 2007 06:13:06 -0700

On 2007-08-26, at 02:37:53, Nigel Garvey wrote:

[…]

Goodness gracious Nigel,
That's blitzingly fast.

I did have one problem on 10.4 with the first line. I changed it to:

set ppath to ((path to desktop as text) & "ppaths.txt")
set allPaths to paragraphs of (read file ppath)

for the purposes of expediency.

I've seen a lot of talk in this thread about associative arrays, Ruby, and Perl, and how mind-bogglingly fast they are, but no actual code. Did that particualr post not make it to the digest?

Nope. But here's a Tcl effort for you to ponder. I output the lists in native format. ~25 lines vs ~175 lines. I'd have to make a few minor adjustments if you want to do the 1000 repetition timing comparison. The "feature" of this associative array example is that I use the file paths as keys and the line number as the value. Normally, one would use the integer as the key because it's a faster lookup.

#!/bin/sh
# Copyright © 2007, Philip Aker. All Rights Reserved \
exec tclsh "$0" "$@"

set fpath [lindex $argv 0];
set f [open $fpath];

set line_number 1;
while {[gets $f line] != -1 } {
array set lnums [list $line_number $line_number];
if {[array exists numbered]} {
if {[llength [array names numbered -exact $line]] > 0} {
array set lnums [list $numbered($line) $numbered($line),$line_number];
}
}
array set numbered [list $line $line_number];
incr line_number;
}
close $f;
puts [array names numbered];
foreach name [array names lnums] {
lappend numlist $lnums($name);
}
puts [lsort -dictionary $numlist];


Philip Aker
email@hidden

 _______________________________________________
Do not post admin requests to the list. They will be ignored.
AppleScript-Users mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
Archives: http://lists.apple.com/archives/applescript-users

This email sent to email@hidden

References: 
 >Re: getting duplicates in a list by item id (From: "Nigel Garvey" <email@hidden>)

  • Prev by Date: Re: Getting the Frontmost Process's Name from the Script Menu
  • Next by Date: Re: Reading and writing records
  • Previous by thread: Re: getting duplicates in a list by item id
  • Next by thread: Re: getting duplicates in a list by item id
  • Index(es):
    • Date
    • Thread