clone in list [Solved]

Got a LiveCode personal license? Are you a beginner, hobbyist or educator that's new to LiveCode? This forum is the place to go for help getting started. Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller

Post Reply
atout66
Posts: 266
Joined: Wed Feb 02, 2011 12:31 pm

clone in list [Solved]

Post by atout66 » Tue Mar 01, 2016 5:01 pm

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:

Code: Select all

"adj,verb,adv,nom,adj,adj,verb"
If I want my list clean just like that:

Code: Select all

"adj,verb,adv,nom"
how do I remove the clones ?

Any idea ?
Thanks in advance, Jean-Paul.
Last edited by atout66 on Tue Mar 01, 2016 5:13 pm, edited 1 time in total.
Discovering LiveCode Community 6.5.2.

Klaus
Posts: 14199
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: clone in list

Post by Klaus » Tue Mar 01, 2016 5:06 pm

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

atout66
Posts: 266
Joined: Wed Feb 02, 2011 12:31 pm

Re: clone in list

Post by atout66 » Tue Mar 01, 2016 5:13 pm

Hi Klaus, thanks for your help :wink:

Your script works fine, but as I'm a bad programmer I don't really understand why :mrgreen:
Discovering LiveCode Community 6.5.2.

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10331
Joined: Wed May 06, 2009 2:28 pm

Re: clone in list

Post by dunbarx » Tue Mar 01, 2016 5:15 pm

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

Klaus
Posts: 14199
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: clone in list

Post by Klaus » Tue Mar 01, 2016 5:35 pm

atout66 wrote:Your script works fine, but as I'm a bad programmer I don't really understand why :mrgreen:
Step through the script in the debugger and you will see :D

atout66
Posts: 266
Joined: Wed Feb 02, 2011 12:31 pm

Re: clone in list [Solved]

Post by atout66 » Tue Mar 01, 2016 6:07 pm

Yeah, you're right and the dictionary too :wink:
Discovering LiveCode Community 6.5.2.

Thierry
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 875
Joined: Wed Nov 22, 2006 3:42 pm

Re: clone in list

Post by Thierry » Tue Mar 01, 2016 6:40 pm

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 :roll:

Regards,

Thierry
!
SUNNY-TDZ.COM doesn't belong to me since 2021.
To contact me, use the Private messages. Merci.
!

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10331
Joined: Wed May 06, 2009 2:28 pm

Re: clone in list [Solved]

Post by dunbarx » Tue Mar 01, 2016 9:22 pm

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

Post Reply