So I’m trying to make a list that contains {“[an arbitrary value]”, “[a word]”} into {“[and arbitrary value]”, “[a word]”, [number of times that word has occurred so far in the sequence]}:
So for example.
Take this list:
{{"269", "It"}, {"439", "was"}, {"509", "the"}, {"829", "best"}, {"1059", "of"}, {"1350", "times"}, {"1449", "it"}, {"2089", "was"}, {"2659", "the"}, {"3250", "worst"}, {"3429", "of"}, {"3529", "times"}, {"4219", "it"}, {"4519", "was"}, {"5210", "the"}, {"5629", "age"}, {"6049", "of"}, {"6279", "wisdom"}, {"6599", "it"}, {"6659", "was"}, {"6839", "the"}, {"7399", "age"}, {"6639", "of"}, {"7639", "foolishness"}, {"8019", "it"}, {"8619", "was"}, {"9369", "the"}, {"9477", "epoch"}, {"9682", "of"}, {"9897", "belief"}}
and make it into this:
{{"269", "It", 1}, {"439", "was", 1}, {"509", "the", 1}, {"829", "best", 1}, {"1059", "of", 1}, {"1350", "times", 1}, {"1449", "it", 2}, {"2089", "was", 2}, {"2659", "the", 2}, {"3250", "worst", 1}, {"3429", "of", 2}, {"3529", "times", 2}, {"4219", "it", 3}, {"4519", "was", 3}, {"5210", "the", 3}, {"5629", "age", 1}, {"6049", "of", 3}, {"6279", "wisdom", 1}, {"6599", "it", 4}, {"6659", "was", 4}, {"6839", "the", 4}, {"7399", "age", 2}, {"of" 4}, {"7639", "foolishness", 1}, {"8019", "it", 4}, {"8619", "was", 5}, {"9369", "the", 5}, {"9477", "epoch", 1}, {"9682", "of", 5}, {"9897", "belief", 1}}
So far all I have is this script that I was able to develop using input from various places on the internet:
set inList to {{"269", "It"}, {"439", "was"}, {"509", "the"}, {"829", "best"}, {"1059", "of"}, {"1350", "times"}, {"1449", "it"}, {"2089", "was"}, {"2659", "the"}, {"3250", "worst"}, {"3429", "of"}, {"3529", "times"}, {"4219", "it"}, {"4519", "was"}, {"5210", "the"}, {"5629", "age"}, {"6049", "of"}, {"6279", "wisdom"}, {"6599", "it"}, {"6659", "was"}, {"6839", "the"}, {"7399", "age"}, {"6639", "of"}, {"7639", "foolishness"}, {"8019", "it"}, {"8619", "was"}, {"9369", "the"}, {"9477", "epoch"}, {"9682", "of"}, {"9897", "belief"}}
set outList to {}
repeat with i from 1 to (length of inList)
set val_and_wrd to item i of inList
set the_word to item 2 of val_and_wrd
set outList to outList & {contents of the_word, 1 + (my countOccurrences(contents of inList, inList))}
end repeat
-- the handler
on countOccurrences(searchWrd, lst)
local counter
set counter to 0
repeat with wordNumPair in lst
if item 2 of wordNumPair is searchWrd then
set counter to counter + 1
end if
end repeat
return counter
end countOccurrences
But it returns this
{"It", 1, "was", 1, "the", 1, "best", 1, "of", 1, "times", 1, "it", 1, "was", 1, "the", 1, "worst", 1, "of", 1, "times", 1, "it", 1, "was", 1, "the", 1, "age", 1, "of", 1, "wisdom", 1, "it", 1, "was", 1, "the", 1, "age", 1, "of", 1, "foolishness", 1, "it", 1, "was", 1, "the", 1, "epoch", 1, "of", 1, "belief", 1}
Not what I’m looking for.
I’m very new to applescript so any help would be greatly appreciated.