Page 1 of 1
clone in list [Solved]
Posted: Tue Mar 01, 2016 5:01 pm
by atout66
Hi to all,
I don't know how to remove clones in a list.
I tried many different
repeat but without success until here...
Let say I have this list:
If I want my list clean just like that:
how do I remove the clones ?
Any idea ?
Thanks in advance, Jean-Paul.
Re: clone in list
Posted: Tue Mar 01, 2016 5:06 pm
by Klaus
Bonjour Jean-Paul,
there is an old trick using an array!
Code: Select all
...
put "adj,verb,adv,nom,adj,adj,verb" into tList1
repeat for each item i in tList1
add 1 to tArray[i]
end repeat
put the keys of tArray into SansClones
replace CR with "," in SansClones
answer SansClones
...
Best
Klaus
Re: clone in list
Posted: Tue Mar 01, 2016 5:13 pm
by atout66
Hi Klaus, thanks for your help
Your script works fine, but as I'm a bad programmer I don't really understand why

Re: clone in list
Posted: Tue Mar 01, 2016 5:15 pm
by dunbarx
What Klaus said. Arrays have their own logic and structure, and can be exploited in just this way.
But you said you had trouble with "repeat". So to be old-fashioned, did anything like this work at all"
Code: Select all
on mouseUp
put "adj,verb,adv,nom,adj,adj,verb" into tList1
repeat for each item tItem in tList1
if tItem is not in accum then put tItem & "," after accum
end repeat
answer accum
end mouseUp
Always good to practice different techniques.
Craig Newman
Re: clone in list
Posted: Tue Mar 01, 2016 5:35 pm
by Klaus
atout66 wrote:Your script works fine, but as I'm a bad programmer I don't really understand why

Step through the script in the debugger and you will see

Re: clone in list [Solved]
Posted: Tue Mar 01, 2016 6:07 pm
by atout66
Yeah, you're right and the dictionary too

Re: clone in list
Posted: Tue Mar 01, 2016 6:40 pm
by Thierry
dunbarx wrote:
Always good to practice different techniques.
Hi Craig,
+1
So, here is another one...
Code: Select all
put replaceText(aList,"\b(\w+),(?=.*\b\1,?)","")
... only to practice different techniques
Regards,
Thierry
Re: clone in list [Solved]
Posted: Tue Mar 01, 2016 9:22 pm
by dunbarx
Thierry.
I have dabbled in regex a bit. So compact, fast and powerful. You are obviously a master.
But so non-X-talk, in a way, if you know what I mean.
@atout66, I assume you will try all three options?
Craig