Sortlist
CADForums.net Forum Index CADForums.net
Discussion of AutoCAD and other CAD software.
 
 FAQFAQ   MemberlistMemberlist     RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 
 
Google
 
Web cadforums.net
Sortlist

 
Post new topic   Reply to topic    CADForums.net Forum Index -> Customization
Author Message
Marcel Janmaat
Guest





Posted: Tue Jan 18, 2005 6:59 pm    Post subject: Sortlist Reply with quote

If i have a somewhat list like this;

( ("" "" "")
("DT" "DETAIL TEKENING" "DETAIL DRAWING")
("BT" "BESTEKTEKENING" "TENDER DRAWING")
("MA" "MILIEU AANVRAAG" "ENVIRONMENTAL APPROVAL")
("MT" "MILIEU TEKENING" "ENVIRONMENTAL DRAWING")
("GV" "GEBRUIKERSVERGUNNING" "USERS APPROVAL")
("BT" "CONTRACTSTUK" "CONTRACT DRAWING")
)

How can i sort this correctly!

It is posible that the first item in each sublist could apear several times
in this list.

At first I used this,

(defun h_sortlist (lst / itm srt new)
(setq srt '())
(foreach itm lst (if (car itm) (setq srt (append srt (list (car itm))))))
(setq srt (acad_strlsort srt) new '())
(foreach itm srt (setq new (append new (list (assoc itm lst)))))
)

But it fails with the assoc beceause "BT" apears twice.

M

Back to top
Doug Broad
Guest





Posted: Tue Jan 18, 2005 7:03 pm    Post subject: Re: Sortlist Reply with quote

Marcel,
You posted an input list and a program that did not work for you.
How do you want the list sorted? Post the result you are looking
for.


"Marcel Janmaat" <m.janmaat@hiensch.nl> wrote in message news:41ed172e_1@newsprd01...
Quote:
If i have a somewhat list like this;

( ("" "" "")
("DT" "DETAIL TEKENING" "DETAIL DRAWING")
("BT" "BESTEKTEKENING" "TENDER DRAWING")
("MA" "MILIEU AANVRAAG" "ENVIRONMENTAL APPROVAL")
("MT" "MILIEU TEKENING" "ENVIRONMENTAL DRAWING")
("GV" "GEBRUIKERSVERGUNNING" "USERS APPROVAL")
("BT" "CONTRACTSTUK" "CONTRACT DRAWING")
)

How can i sort this correctly!

It is posible that the first item in each sublist could apear several times
in this list.

At first I used this,

(defun h_sortlist (lst / itm srt new)
(setq srt '())
(foreach itm lst (if (car itm) (setq srt (append srt (list (car itm))))))
(setq srt (acad_strlsort srt) new '())
(foreach itm srt (setq new (append new (list (assoc itm lst)))))
)

But it fails with the assoc beceause "BT" apears twice.

M

Back to top
Marcel Janmaat
Guest





Posted: Tue Jan 18, 2005 7:07 pm    Post subject: Re: Sortlist Reply with quote

The result has to look like this;

( ("" "" "")
("BT" "BESTEKTEKENING" "TENDER DRAWING")
("BT" "CONTRACTSTUK" "CONTRACT DRAWING")
("DT" "DETAIL TEKENING" "DETAIL DRAWING")
("GV" "GEBRUIKERSVERGUNNING" "USERS APPROVAL")
("MA" "MILIEU AANVRAAG" "ENVIRONMENTAL APPROVAL")
("MT" "MILIEU TEKENING" "ENVIRONMENTAL DRAWING")
)


"Doug Broad" <dbroad-no@spam-nash.cc.nc.us> schreef in bericht
news:41ed17da_3@newsprd01...
Quote:
Marcel,
You posted an input list and a program that did not work for you.
How do you want the list sorted? Post the result you are looking
for.


"Marcel Janmaat" <m.janmaat@hiensch.nl> wrote in message
news:41ed172e_1@newsprd01...
If i have a somewhat list like this;

( ("" "" "")
("DT" "DETAIL TEKENING" "DETAIL DRAWING")
("BT" "BESTEKTEKENING" "TENDER DRAWING")
("MA" "MILIEU AANVRAAG" "ENVIRONMENTAL APPROVAL")
("MT" "MILIEU TEKENING" "ENVIRONMENTAL DRAWING")
("GV" "GEBRUIKERSVERGUNNING" "USERS APPROVAL")
("BT" "CONTRACTSTUK" "CONTRACT DRAWING")
)

How can i sort this correctly!

It is posible that the first item in each sublist could apear several
times
in this list.

At first I used this,

(defun h_sortlist (lst / itm srt new)
(setq srt '())
(foreach itm lst (if (car itm) (setq srt (append srt (list (car
itm))))))
(setq srt (acad_strlsort srt) new '())
(foreach itm srt (setq new (append new (list (assoc itm lst)))))
)

But it fails with the assoc beceause "BT" apears twice.

M





Back to top
Doug Broad
Guest





Posted: Tue Jan 18, 2005 8:02 pm    Post subject: Re: Sortlist Reply with quote

Marcel,
For your particular list vl-sort works fine. You should be aware, however,
that for some lists, vl-sort removes duplicates.

Assuming that your list is stored in variable b:

(vl-sort b '(lambda (a b)(< (car a)(car b))))


"Marcel Janmaat" <m.janmaat@hiensch.nl> wrote in message news:41ed191f$1_3@newsprd01...
Quote:
The result has to look like this;

( ("" "" "")
("BT" "BESTEKTEKENING" "TENDER DRAWING")
("BT" "CONTRACTSTUK" "CONTRACT DRAWING")
("DT" "DETAIL TEKENING" "DETAIL DRAWING")
("GV" "GEBRUIKERSVERGUNNING" "USERS APPROVAL")
("MA" "MILIEU AANVRAAG" "ENVIRONMENTAL APPROVAL")
("MT" "MILIEU TEKENING" "ENVIRONMENTAL DRAWING")
)


"Doug Broad" <dbroad-no@spam-nash.cc.nc.us> schreef in bericht
news:41ed17da_3@newsprd01...
Marcel,
You posted an input list and a program that did not work for you.
How do you want the list sorted? Post the result you are looking
for.


"Marcel Janmaat" <m.janmaat@hiensch.nl> wrote in message
news:41ed172e_1@newsprd01...
If i have a somewhat list like this;

( ("" "" "")
("DT" "DETAIL TEKENING" "DETAIL DRAWING")
("BT" "BESTEKTEKENING" "TENDER DRAWING")
("MA" "MILIEU AANVRAAG" "ENVIRONMENTAL APPROVAL")
("MT" "MILIEU TEKENING" "ENVIRONMENTAL DRAWING")
("GV" "GEBRUIKERSVERGUNNING" "USERS APPROVAL")
("BT" "CONTRACTSTUK" "CONTRACT DRAWING")
)

How can i sort this correctly!

It is posible that the first item in each sublist could apear several
times
in this list.

At first I used this,

(defun h_sortlist (lst / itm srt new)
(setq srt '())
(foreach itm lst (if (car itm) (setq srt (append srt (list (car
itm))))))
(setq srt (acad_strlsort srt) new '())
(foreach itm srt (setq new (append new (list (assoc itm lst)))))
)

But it fails with the assoc beceause "BT" apears twice.

M





Back to top
Fatty
Guest





Posted: Tue Jan 18, 2005 11:03 pm    Post subject: Re: Sortlist Reply with quote

Of course, if you take vl-sort function then ...
"duplicate elements may be eliminated from the list."
There are many ways to do this,
it is somewhat brutal but should work.

(setq nth_lst (vl-sort-i
<your list>
(function (lambda (e1 e2)
(< (car e1)(car e2))))))
(setq ret_list
(mapcar (function (lambda (x)
(nth x <your list>)))
nth_lst))
Back to top
Ray Schiska
Guest





Posted: Mon Dec 05, 2005 9:10 am    Post subject: Re: Sortlist Reply with quote

Fatty <nospam@address.withheld> wrote:

Quote:
Of course, if you take vl-sort function then ...
"duplicate elements may be eliminated from the list."
There are many ways to do this,
it is somewhat brutal but should work.

(setq nth_lst (vl-sort-i
<your list
(function (lambda (e1 e2)
(< (car e1)(car e2))))))
(setq ret_list
(mapcar (function (lambda (x)
(nth x <your list>)))
nth_lst))

On Tue, 18 Jan 2005 18:03:18 GMT, you wrote:

Quote:
Of course, if you take vl-sort function then ...
"duplicate elements may be eliminated from the list."
There are many ways to do this,
it is somewhat brutal but should work.

(setq nth_lst (vl-sort-i
<your list
(function (lambda (e1 e2)
(< (car e1)(car e2))))))
(setq ret_list
(mapcar (function (lambda (x)
(nth x <your list>)))
nth_lst))


Hey Fatty??,

I don't know if you are still monitoring this group, but I would like
to respond to the above post. I am dealing with very large (thousands
of 3 element entries) lists of lists and so have been looking for as
fast a sorter as I can find. I have looked at about 8 so far. I was
browsing thru here and just happened to see yer post- I had seen your
name in ADESKs" VBA and Custominzation" area b4 - it kinda stands out
ya know? Anyway, on an impulse I captured yer code and plugged it in
and gave it a go and it is the fastest sorter I have yet to use. Your
comments sounded sort of deprecating so I didn't expect much, so I was
pleasantly surprised with the results. It is twice as fast as the
fastest one I have found so far and SIGNIFIGANTLY faster than the
routines from an individual who is reputed to be an expert on sorting.
I won't mention a name but, yours blew it away. Anyway, I just
thought you might like to know. Thanks for the code. Hmm-m-m-m, you
might be some one I could ask about a problem I am having with one of
my routines. I hope I am not being presumptuous but here goes...

As I said I have large lists that Iam working that always have 3 ents
each, an Int and two reals. For example: "1000 5280.5280 2640.26"
would be a typical sub-list. Accessing these by indexing on the INT
is so easy even I can do it, but I have a need to search through this
list of lists for an exact match of ents # 2 and 3 and return the
whole list or at least the Int if I find a match. For some reason I
am struggling with this... I am sure a part of the problem is that
I've only been working in Lisp for a few weeks now and am grappling
with a lot of new concepts. But that's of no mind and I would
appreciate if you have any thoughts on this and could get me at least
pointed in the right direction. If not I will probably screw up my
courage and paste this problem to the ADESK site. I have been
spending a lot of time monitoring these sites to pick up knowledge,
but have yet to post directly. Anyway, thanks for taking the time to
read this...

Sincerely,
Ray Schiska
Back to top
 
Post new topic   Reply to topic    CADForums.net Forum Index -> Customization All times are GMT
Page 1 of 1

 
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum




Windows Server DSP VoIP Electronics New Topics
Powered by phpBB