• 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: "Mark J. Reed" <email@hidden>
  • Date: Sun, 26 Aug 2007 11:36:38 -0400

On 8/26/07, Mark J. Reed <email@hidden> wrote:
> Here's the complete Ruby program.

Well, that's the one I ran.  To be somewhat more useful, this version
sorts the output by line number of first occurrence, and calls the
first line 1 instead of 0:

pathList = File.readlines('paths.txt')

pathPositions = {}

pathList.each_with_index do |path, position|
    path.chomp!
    (pathPositions[path] ||= []).push(position + 1)
end

pathPositions.sort { |a, b| a[1][0] <=> b[1][0] }.each do |path, positions|
    puts "#{path} - #{positions.join(',')}"
end




And here's the equivalent Perl:

open(my $fileHandle, "<paths.txt");
chomp(my @pathList = <$fileHandle>);
close($fileHandle);

my %pathPositions;

for (my $position = 0; $position < @pathList; ++$position)
{
    my $path = $pathList[$position];
    push (@{$pathPositions{$path} ||= []}, $position + 1);
}

foreach my $path
 (sort { $pathPositions{$a}[0] <=> $pathPositions{$b}[0] } keys %pathPositions)
{
    my $positions = $pathPositions{$path};
    print "$path - ", join(',', @$positions), "\n";
}
 _______________________________________________
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>)
 >Re: getting duplicates in a list by item id (From: "Mark J. Reed" <email@hidden>)

  • Prev by Date: Re: getting duplicates in a list by item id
  • Next by Date: Re: Reading and writing records
  • Previous by thread: Re: getting duplicates in a list by item id
  • Next by thread: Resizing in Photoshop
  • Index(es):
    • Date
    • Thread