Delete BOTH duplicates from a LIST
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller
Delete BOTH duplicates from a LIST
Hi all,
I'm trying to find a very fast way to delete BOTH duplicates from a list. For instance if I have a list:
apple
orange
apple
apple
banana
I want to return
orange
banana
I know about the array workaround, but it keeps ONE of them. Other than brute force (repeat for each line L), is there any *faster* way to do this?
Thanks!
			
			
									
									I'm trying to find a very fast way to delete BOTH duplicates from a list. For instance if I have a list:
apple
orange
apple
apple
banana
I want to return
orange
banana
I know about the array workaround, but it keeps ONE of them. Other than brute force (repeat for each line L), is there any *faster* way to do this?
Thanks!
[url=http://www.altuit.com/webs/hemingway/Products/AltuitProducts.htm]Visit Altuit, creator of ButtonGadget and other Rev add-ons[/url]
						Re: Delete BOTH duplicates from a LIST
Hi, Chipp.
Your example suggests you meant ALL, not just both.
If you want to exclude any item that appears more than once in a list, you could do it like this:
Is that what you seek?  Is it fast enough?
-- Dick
			
			
									
									
						Your example suggests you meant ALL, not just both.
If you want to exclude any item that appears more than once in a list, you could do it like this:
Code: Select all
on mouseUp
    local tList
    put "apple,orange,apple,apple,banana" into tList
    replace comma with cr in tList
    get getLinesThatAppearOnlyOnce( tList )
    breakpoint
end mouseUp
function getLinesThatAppearOnlyOnce pList
    local tCountForLine
    repeat for each line tLine in pList
        add 1 to tCountForLine[ tLine ]
    end repeat
    repeat for each key tLine in tCountForLine
        if tCountForLine[ tLine ] > 1 then
            delete variable tCountForLine[ tLine ]
        end if
    end repeat
    return the keys of tCountForLine
end getLinesThatAppearOnlyOnce-- Dick
Re: Delete BOTH duplicates from a LIST
Hello Chip,I'm trying to find a very fast way to delete BOTH duplicates from a list.
Here are 2 versions... (with exactly the same result)
Code: Select all
function F1 L1
   local L2,  A
   repeat for each line L in L1
      add 1 to A[ L]
   end repeat
   repeat for each key K in A
      if A[ K] > 1 then next repeat
      put K &cr after L2
   end repeat
   -- delete last char of L2 -- maybe needed?
   return L2
end F1Code: Select all
function F2 L1
   sort L1
   get replacetext( L1, "(?m)^(.*)(\n?\n\1)+$", empty)
   filter lines of IT without empty
   return IT
end F2Thierry
PS: coding the 2nd one was more fun

!
SUNNY-TDZ.COM doesn't belong to me since 2021.
To contact me, use the Private messages. Merci.
!
						SUNNY-TDZ.COM doesn't belong to me since 2021.
To contact me, use the Private messages. Merci.
!
Re: Delete BOTH duplicates from a LIST
I used to be a newbie but then I learned how to spell teh correctly and now I'm a noob!
						Re: Delete BOTH duplicates from a LIST
and get rid of the filter..Thierry wrote:Code: Select all
function F2 L1 sort L1 get replacetext( L1, "(?m)^(.*)(\n?\n\1)+$", empty) filter lines of IT without empty return IT end F2
Code: Select all
function F2 L1
   sort L1
   return replacetext( L1,  "(?m)^(.*)(\n?\n\1)+(\n|$)" , empty)
end F2!
SUNNY-TDZ.COM doesn't belong to me since 2021.
To contact me, use the Private messages. Merci.
!
						SUNNY-TDZ.COM doesn't belong to me since 2021.
To contact me, use the Private messages. Merci.
!
Re: Delete BOTH duplicates from a LIST
Wow guys, thanks!   EXACTLY what I was looking for!
  EXACTLY what I was looking for!
			
			
									
									 EXACTLY what I was looking for!
  EXACTLY what I was looking for![url=http://www.altuit.com/webs/hemingway/Products/AltuitProducts.htm]Visit Altuit, creator of ButtonGadget and other Rev add-ons[/url]
						- 
				richmond62
- Livecode Opensource Backer 
- Posts: 10202
- Joined: Fri Feb 19, 2010 10:17 am
Re: Delete BOTH duplicates from a LIST
Really primitive proof of concept:
https://www.dropbox.com/sh/ja47l87gg87s ... C5ORa?dl=0
Download the file called "weeding.zip"
			
			
									
									
						https://www.dropbox.com/sh/ja47l87gg87s ... C5ORa?dl=0
Download the file called "weeding.zip"
