Jump to content

duplicate items on list


pBe

Recommended Posts

one more query while you're at it...

 

(setq dd '("8" "11" "8" "9" "10" "11" "7" "12")
n_lst
(LM:UNIQUE dd))
("8" "11" "9" "10" "7" "12")

(mapcar 'chr (vl-sort (mapcar 'ascii dd) '<))
("1" "7" "8" "9")

why is it ignoring "11" & "12"?

 

As I said, the vl-sort method should really be used for removing duplcates - re-read my post #8

 

The reason it ignores 11 and 12 is because that method looks at the Character code of the first character - in this case 11 and 12 are the same = 1.

Link to comment
Share on other sites

  • Replies 28
  • Created
  • Last Reply

Top Posters In This Topic

  • Lee Mac

    11

  • pBe

    10

  • m4rdy

    2

  • Lt Dan's legs

    2

Top Posters In This Topic

i could do it this way...

(defun c:sort_test ()
(setq ls_vl '("12" "2" "C" "A" "4" "B" "5" "6" "7" "D" "8" "9" "E" "10" "11" "1"))
(foreach dg ls_vl
  (if (> (atoi  dg) 0)
    (setq N_ls (cons (atoi dg) N_ls))
    (setq L_ls (cons dg L_ls))
  )
)    
(setq L_ls (vl-sort L_ls '<)
n_ls (mapcar 'itoa 
  (vl-sort N_ls '<)))
(princ  L_ls)(princ N_ls)(princ)   
)

 

after removal of duplicates i'll run this

 

What do you guys think?

Link to comment
Share on other sites

Here's the iterative version of my earlier post - not much difference in performance really:

 

(defun LM:Unique_iter ( l / r )
 (while (setq x (car l)) (setq r (cons x r) l (vl-remove x (cdr l))))
 (reverse r)
)

(defun LM:Unique ( l )
 (if l (cons (car l) (LM:Unique (vl-remove (car l) (cdr l)))))
)

 

List Length: 1280
Benchmarking ................Elapsed milliseconds / relative speed for 8192 iteration(s):

   (LM:UNIQUE L)........................1747 / 7.38 <fastest>
   (LM:UNIQUE_ITER L)...................1748 / 7.37
   (REMOVEDUPLICATES L).................4602 / 2.80
   (MIP_MAKEUNIQUEMEMBERSOFLIST L).....12885 / 1.00 <slowest>

 

List Length: 1280
Benchmarking ................Elapsed milliseconds / relative speed for 8192 iteration(s):

   (LM:UNIQUE_ITER L).....1716 / 1.01 <fastest>
   (LM:UNIQUE L)..........1732 / 1.00 <slowest>

Link to comment
Share on other sites

if i use that Lee here's the result

(acad_strlsort (LM:Unique ls_vl))
("1" "10" "11" "12" "2" "4" "5" "6" "7" "8" "9" "A" "B" "C" "D" "E")

 

see where "10" and "11" is? for some reason i cant explain i need the list to be in order and in string format... plus i need to work on tracking missing number/letter tooi.e ("1" "2" "4" "5" "A" "B" "C" "E") something like that

 

No worries Lee Mac.. really like the way you write codes though.. complex but short (really short) :)

 

i think i'm happy with the sorting code i wrote... thanks a mil everyone

 

You know what guys i just realized something.. i really dont need the number list to be in order as a string..

my goal in the first place is grab the last number.. i just leave it as an integer list and grab the highest number using max

how di i miss that.. but then again.. thank you for the cool duplicate removal Lee :D

Edited by pBe
Light bulb on my head
Link to comment
Share on other sites

How about something like:

 

(defun Sort ( l )
 (vl-sort l
   (function
     (lambda ( a b / c d )
       (if (and (setq c (distof a)) (setq d (distof b)))
         (< c d)
         (< a b)
       )
     )
   )
 )
)

Link to comment
Share on other sites

How about something like:

 

(defun Sort ( l )
(vl-sort l
(function
(lambda ( a b / c d )
(if (and (setq c (distof a)) (setq d (distof b)))
(< c d)
(< a b)
)
)
)
)
)

 

Again, you made it shorter than what i had... How do you do it Lee :)

I noticed you used lambda from time to time.... boy.. i'm petrified of it , i never used it, no wonder my codes are a mile long... i've seen it on C and Python language

maybe bacause i dont really understand it :lol:

 

Mathematics is killing me....

 

 

Thank you Lee

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


×
×
  • Create New...