Author Topic: Puzzle: flat list to nested indexed list  (Read 357 times)

0 Members and 1 Guest are viewing this topic.

Marc'Antonio Alessi

  • Swamp Rat
  • Posts: 776
  • Marco
Puzzle: flat list to nested indexed list
« on: December 07, 2017, 05:23:14 am »


Maybe something similar has already been done, if someone remembers something like this...

how to get a nested indexed list from a flat list.
In_List  > length 1000
Out_List > 3 level each level is length 10
the contents of each line can be anything:
"SubFoo "      "Cl Foo"        "Foo "     "Description A"             "Foo B"           "F Measure mmm"
Code: [Select]

In_List '(
("SubGroup 0" "Class 00" "SubClass 000" "000 DescriptionA" "000 DescriptionB" "000 Measure")
("SubGroup 0" "Class 00" "SubClass 001" "001 DescriptionA" "001 DescriptionB" "001 Measure")
("SubGroup 0" "Class 00" "SubClass 002" "002 DescriptionA" "002 DescriptionB" "002 Measure")
...
("SubGroup 0" "Class 01" "SubClass 010" "010 DescriptionA" "010 DescriptionB" "010 Measure")
("SubGroup 0" "Class 01" "SubClass 011" "011 DescriptionA" "011 DescriptionB" "011 Measure")
("SubGroup 0" "Class 01" "SubClass 012" "012 DescriptionA" "012 DescriptionB" "012 Measure")
...
("SubGroup 0" "Class 02" "SubClass 020" "020 DescriptionA" "020 DescriptionB" "020 Measure")
("SubGroup 0" "Class 02" "SubClass 021" "021 DescriptionA" "021 DescriptionB" "021 Measure")
("SubGroup 0" "Class 02" "SubClass 022" "022 DescriptionA" "022 DescriptionB" "022 Measure")
...
("SubGroup 1" "Class 10" "SubClass 100" "100 DescriptionA" "100 DescriptionB" "100 Measure")
("SubGroup 1" "Class 10" "SubClass 101" "101 DescriptionA" "101 DescriptionB" "101 Measure")
("SubGroup 1" "Class 10" "SubClass 102" "102 DescriptionA" "102 DescriptionB" "102 Measure")
...
("SubGroup 1" "Class 11" "SubClass 110" "110 DescriptionA" "110 DescriptionB" "110 Measure")
("SubGroup 1" "Class 11" "SubClass 111" "111 DescriptionA" "111 DescriptionB" "111 Measure")
("SubGroup 1" "Class 11" "SubClass 112" "112 DescriptionA" "112 DescriptionB" "112 Measure")
...
("SubGroup 1" "Class 12" "SubClass 120" "120 DescriptionA" "120 DescriptionB" "120 Measure")
("SubGroup 1" "Class 12" "SubClass 121" "121 DescriptionA" "121 DescriptionB" "121 Measure")
("SubGroup 1" "Class 12" "SubClass 122" "122 DescriptionA" "122 DescriptionB" "122 Measure")
... last item is:
("SubGroup 9" "Class 99" "SubClass 999" "999 DescriptionA" "999 DescriptionB" "999 Measure")
)
Code: [Select]
Out_List '(
(0 "SubGroup 0"
  (0 "Class 00"
    (0 "SubClass 000" "000 DescriptionA" "000 DescriptionB" "000 Measure")
    (1 "SubClass 001" "001 DescriptionA" "001 DescriptionB" "001 Measure")
    (2 "SubClass 002" "002 DescriptionA" "002 DescriptionB" "002 Measure")
    ...
  )
  (1 "Class 01"
    (0 "SubClass 010" "010 DescriptionA" "010 DescriptionB" "010 Measure")
    (1 "SubClass 011" "011 DescriptionA" "011 DescriptionB" "011 Measure")
    (2 "SubClass 012" "012 DescriptionA" "012 DescriptionB" "012 Measure")
    ...
  )
  (2 "Class 02"
    (0 "SubClass 020" "020 DescriptionA" "020 DescriptionB" "020 Measure")
    (1 "SubClass 021" "021 DescriptionA" "021 DescriptionB" "021 Measure")
    (2 "SubClass 022" "022 DescriptionA" "022 DescriptionB" "022 Measure")
  )
  ...
)(1 "SubGroup 1"
  (0 "Class 10"
    (0 "SubClass 100" "100 DescriptionA" "100 DescriptionB" "100 Measure")
    (1 "SubClass 101" "101 DescriptionA" "101 DescriptionB" "101 Measure")
    (2 "SubClass 102" "102 DescriptionA" "102 DescriptionB" "102 Measure")
    ...
  )
  (1 "Class 11"
    (0 "SubClass 110" "110 DescriptionA" "110 DescriptionB" "110 Measure")
    (1 "SubClass 111" "111 DescriptionA" "111 DescriptionB" "111 Measure")
    (2 "SubClass 112" "112 DescriptionA" "112 DescriptionB" "112 Measure")
    ...
  )
  (2 "Class 12"
    (0 "SubClass 120" "120 DescriptionA" "120 DescriptionB" "120 Measure")
    (1 "SubClass 121" "121 DescriptionA" "121 DescriptionB" "121 Measure")
    (2 "SubClass 122" "122 DescriptionA" "122 DescriptionB" "122 Measure")
    ...
  )
  ...
)
... last item is:
(9 "SubGroup 9"
  (0 "Class 90"
    (0 "SubClass 900" "900 DescriptionA" "900 DescriptionB" "900 Measure")
    (1 "SubClass 901" "901 DescriptionA" "901 DescriptionB" "901 Measure")
    (2 "SubClass 902" "902 DescriptionA" "902 DescriptionB" "902 Measure")
    ...
  )
...
  (9 "Class 99"
    ... last item is:
    (9 "SubClass 999" "999 DescriptionA" "999 DescriptionB" "999 Measure")
  )
)
)
Code: [Select]
The goal is:
(defun Dxf (DxfCod EntDat)  (cdr (assoc DxfCod EntDat)))


To find the DescriptionB of SubClass 999:
(caddr (DXF 9 (cdr (DXF 9 (cdr (DXF 9 Out_List)))))))             => "999 DescriptionB"


(setq Pfx_SG 7   Pfx_CL 8   Pfx_SC 4)


To find the Description of SubGroup:
(DXF Pfx_SG Out_List)                                             => "SubGroup 7"


To find the Description of Class:
(car (DXF Pfx_CL (cdr (DXF Pfx_SG Out_List))))                    => "Class 78"


To find the Description of SubClass:
(car (DXF Pfx_SC (cdr (DXF Pfx_CL (cdr (DXF Pfx_SG Out_List)))))) => "SubClass 784"
« Last Edit: December 09, 2017, 06:23:24 am by Marc'Antonio Alessi »
Marc'Antonio Alessi http://alessi.xoom.it//alessi/  Coding manual: http://tinyurl.com/zza7ega

roy_043

  • Water Moccasin
  • Posts: 1513
  • BricsCAD 16
Re: Puzzle: flat list to nested indexed list
« Reply #1 on: December 08, 2017, 05:29:51 am »
My approach:
Code - Auto/Visual Lisp: [Select]
  1. ; Divide a list into sublists with a fixed length. The last sublist in
  2. ; the return value can contain less elements than the other sublists.
  3. ; (KGA_List_Divide '(1 2 3 4 5 6 7 8) 3) => ((1 2 3) (4 5 6) (7 8))
  4. (defun KGA_List_Divide (lst n / i ret tmp)
  5.  (if lst
  6.    (progn
  7.      (setq i n)
  8.      (mapcar
  9.        '(lambda (a)
  10.          (if (zerop i)
  11.            (progn
  12.              (setq ret (cons (reverse tmp) ret))
  13.              (setq tmp nil)
  14.              (setq i n)
  15.            )
  16.          )
  17.          (setq tmp (cons a tmp))
  18.          (setq i (1- i))
  19.        )
  20.        lst
  21.      )
  22.      (reverse (cons (reverse tmp) ret))
  23.    )
  24.  )
  25. )
  26.  
  27. (defun DoAssoc (lst / fnd ret)
  28.  (foreach sub lst
  29.    (if (setq fnd (assoc (car sub) ret))
  30.      (setq ret (subst (append (list (car sub) (cdr sub)) (cdr fnd)) fnd ret))
  31.      (setq ret (cons (list (car sub) (cdr sub)) ret))
  32.    )
  33.  )
  34.    (mapcar
  35.      '(lambda (sub) (cons (car sub) (reverse (cdr sub))))
  36.      ret
  37.    )
  38.  )
  39. )
  40.  
  41. ; (Doit In_List)
  42. (defun DoIt (lst)
  43.  (mapcar
  44.    '(lambda (sub)
  45.      (cons (car sub) (DoAssoc (cdr sub)))
  46.    )
  47.    (DoAssoc (KGA_List_Divide lst 6))
  48.  )
  49. )

Marc'Antonio Alessi

  • Swamp Rat
  • Posts: 776
  • Marco
Re: Puzzle: flat list to nested indexed list
« Reply #2 on: December 08, 2017, 07:25:11 am »

My approach:
...
Thanks Roy I will try it.  :)
Marc'Antonio Alessi http://alessi.xoom.it//alessi/  Coding manual: http://tinyurl.com/zza7ega

Lee Mac

  • Seagull
  • Posts: 11854
  • AutoCAD 2015 Windows 7 London, England
Re: Puzzle: flat list to nested indexed list
« Reply #3 on: December 08, 2017, 01:04:40 pm »
You've actually already written a function to perform this operation in this thread:wink:

Marc'Antonio Alessi

  • Swamp Rat
  • Posts: 776
  • Marco
Re: Puzzle: flat list to nested indexed list
« Reply #4 on: December 08, 2017, 02:58:14 pm »

You've actually already written a function to perform this operation in this thread;)
Code: [Select]
Thanks Lee but it's not the same thing:
>>> the contents of each line can be anything:
>>> "SubFoo "      "Cl Foo"        "Foo "     "Description A"             "Foo B"           "F Measure mmm"
there are no keys in the list, only the position in the list determines the key
now I'm trying to populate the list in a file so I can use it without recreating it every time
Code: [Select]
; sample for 3 level list each level is length 3 (NOT working)
(defun test (In_List / )
    (setq FilLsp "C:\\Temp\\Group6Info.lsp")           
      (setq FilPnt (open FilLsp "w")  Cur_SG 0  Cur_CL 0  Cur_SC 0)
      (write-line "(setq #Group6Info '(" FilPnt)             
      (foreach ForItm In_List
        (cond
          ( (= Cur_CL 0)
            (write-line "(" FilPnt) (prin1 Cur_SG FilPnt) (prin1 (car   ForItm) FilPnt)
            (write-line "(" FilPnt) (prin1 Cur_CL FilPnt) (prin1 (cadr  ForItm) FilPnt)
            (write-line "(" FilPnt) (prin1 Cur_SC FilPnt) (prin1 (caddr ForItm) FilPnt)
               (prin1 (nth 3 ForItm)) (prin1 (nth 4 ForItm))(prin1 (nth 5 ForItm)) (prin1 ")" FilPnt)
            (setq Cur_SC (1+ Cur_SC))
          )
          ( (and (= Cur_CL 2) (= Cur_SC 2))
            (write-line "(" FilPnt) (prin1 Cur_SC FilPnt) (prin1 (caddr ForItm) FilPnt) (prin1 (nth 3 ForItm))
            (prin1 (nth 4 ForItm))(prin1 (nth 5 ForItm)) (prin1 ")" FilPnt)
            (write-line ")" FilPnt)
            (write-line ")" FilPnt)
            (setq Cur_SG (1+ Cur_SG)  Cur_CL 0  Cur_SC 0)
          )
          ( T
                (write-line "(" FilPnt) (prin1 Cur_SC FilPnt) (prin1 (caddr ForItm) FilPnt) (prin1 (nth 3 ForItm))
                (prin1 (nth 4 ForItm))(prin1 (nth 5 ForItm)) (prin1 ")" FilPnt)
                (setq Cur_SC (1+ Cur_SC))
          )
        )
      )
      (write-line "))" FilPnt)
      (close FilPnt)
)
(setq In_List '(
("SubGroup 0" "Class 00" "SubClass 000" "000 DescriptionA" "000 DescriptionB" "000 Measure")
("SubGroup 0" "Class 00" "SubClass 001" "001 DescriptionA" "001 DescriptionB" "001 Measure")
("SubGroup 0" "Class 00" "SubClass 002" "002 DescriptionA" "002 DescriptionB" "002 Measure")
("SubGroup 0" "Class 01" "SubClass 010" "010 DescriptionA" "010 DescriptionB" "010 Measure")
("SubGroup 0" "Class 01" "SubClass 011" "011 DescriptionA" "011 DescriptionB" "011 Measure")
("SubGroup 0" "Class 01" "SubClass 012" "012 DescriptionA" "012 DescriptionB" "012 Measure")
("SubGroup 0" "Class 02" "SubClass 020" "020 DescriptionA" "020 DescriptionB" "020 Measure")
("SubGroup 0" "Class 02" "SubClass 021" "021 DescriptionA" "021 DescriptionB" "021 Measure")
("SubGroup 0" "Class 02" "SubClass 022" "022 DescriptionA" "022 DescriptionB" "022 Measure")
("SubGroup 1" "Class 10" "SubClass 100" "100 DescriptionA" "100 DescriptionB" "100 Measure")
("SubGroup 1" "Class 10" "SubClass 101" "101 DescriptionA" "101 DescriptionB" "101 Measure")
("SubGroup 1" "Class 10" "SubClass 102" "102 DescriptionA" "102 DescriptionB" "102 Measure")
("SubGroup 1" "Class 11" "SubClass 110" "110 DescriptionA" "110 DescriptionB" "110 Measure")
("SubGroup 1" "Class 11" "SubClass 111" "111 DescriptionA" "111 DescriptionB" "111 Measure")
("SubGroup 1" "Class 11" "SubClass 112" "112 DescriptionA" "112 DescriptionB" "112 Measure")
("SubGroup 1" "Class 12" "SubClass 120" "120 DescriptionA" "120 DescriptionB" "120 Measure")
("SubGroup 1" "Class 12" "SubClass 121" "121 DescriptionA" "121 DescriptionB" "121 Measure")
("SubGroup 1" "Class 12" "SubClass 122" "122 DescriptionA" "122 DescriptionB" "122 Measure")
("SubGroup 2" "Class 20" "SubClass 200" "200 DescriptionA" "200 DescriptionB" "200 Measure")
("SubGroup 2" "Class 20" "SubClass 201" "201 DescriptionA" "201 DescriptionB" "201 Measure")
("SubGroup 2" "Class 20" "SubClass 202" "202 DescriptionA" "202 DescriptionB" "202 Measure")
("SubGroup 2" "Class 21" "SubClass 210" "210 DescriptionA" "210 DescriptionB" "210 Measure")
("SubGroup 2" "Class 21" "SubClass 211" "211 DescriptionA" "211 DescriptionB" "211 Measure")
("SubGroup 2" "Class 21" "SubClass 212" "212 DescriptionA" "212 DescriptionB" "212 Measure")
("SubGroup 2" "Class 22" "SubClass 220" "220 DescriptionA" "220 DescriptionB" "220 Measure")
("SubGroup 2" "Class 22" "SubClass 221" "221 DescriptionA" "221 DescriptionB" "221 Measure")
("SubGroup 2" "Class 22" "SubClass 222" "222 DescriptionA" "222 DescriptionB" "222 Measure")
))

(test In_List)
Marc'Antonio Alessi http://alessi.xoom.it//alessi/  Coding manual: http://tinyurl.com/zza7ega

Grrr1337

  • Bull Frog
  • Posts: 453
Re: Puzzle: flat list to nested indexed list
« Reply #5 on: December 08, 2017, 03:30:24 pm »
I think that the suggested codes in Split List Using Test Function thread might be handy, then use GroupByN on the list result, where n=2.

Lee Mac

  • Seagull
  • Posts: 11854
  • AutoCAD 2015 Windows 7 London, England
Re: Puzzle: flat list to nested indexed list
« Reply #6 on: December 08, 2017, 04:15:37 pm »
You've actually already written a function to perform this operation in this thread;)
Thanks Lee but it's not the same thing:
>>> the contents of each line can be anything:
>>> "SubFoo "      "Cl Foo"        "Foo "     "Description A"             "Foo B"           "F Measure mmm"
there are no keys in the list, only the position in the list determines the key

Using the first function I posted in that thread on the in_list list provided in your post above, the following should yield the desired result, no?
Code - Auto/Visual Lisp: [Select]
  1. (mapcar '(lambda ( x ) (cons (car x) (groupbykey (cdr x)))) (groupbykey in_list))

Grrr1337

  • Bull Frog
  • Posts: 453
Re: Puzzle: flat list to nested indexed list
« Reply #7 on: December 08, 2017, 04:53:42 pm »
Using the first function I posted in that thread on the in_list list provided in your post above, the following should yield the desired result, no?
Code - Auto/Visual Lisp: [Select]
  1. (mapcar '(lambda ( x ) (cons (car x) (groupbykey (cdr x)))) (groupbykey in_list))

Works, for the last in_list that Marco provided - which is list of lists of strings.
The very first (original) one in_list which is list of strings, should be processed a bit...
...with the subfunctions you wrote and that example you provided!  :-D

Initially defining...
Code - Auto/Visual Lisp: [Select]
  1. (defun SplitByTf ( prd lst / rtn tmp )
  2.  ; Lee Mac ; https://www.theswamp.org/index.php?topic=53354.msg580794#msg580794
  3.  (foreach itm lst
  4.    (if (apply prd (list itm))
  5.      (progn
  6.        (if tmp (setq rtn (cons (reverse tmp) rtn)))
  7.        (setq rtn (cons (list itm) rtn)
  8.          tmp nil
  9.        )
  10.      )
  11.      (setq tmp (cons itm tmp))
  12.    )
  13.  )
  14.  (reverse (if tmp (cons (reverse tmp) rtn) rtn))
  15. )
  16.  
  17. ; _$ (GroupBy2 '(1 2 3 4 5 6 7)) -> ((1 2) (3 4) (5 6) (7))
  18. (defun GroupBy2 ( L / tmp ) (cond ( (not L) L) ( (cons (append (if (setq tmp (car L)) (list tmp)) (if (setq tmp (cadr L)) (list tmp))) (GroupBy2 (cddr L))) ) ))
  19.  
  20. (defun groupbykey ( lst / rtn tmp )
  21.  ; Lee Mac ; https://www.theswamp.org/index.php?topic=53515.0
  22.  (foreach itm (reverse lst)
  23.    (if (setq tmp (assoc (car itm) rtn))
  24.      (setq rtn (subst (vl-list* (car itm) (cdr itm) (cdr tmp)) tmp rtn))
  25.      (setq rtn (cons  (list (car itm) (cdr itm)) rtn))
  26.    )
  27.  )
  28. )

and then:
Code: [Select]
(mapcar '(lambda ( x ) (cons (car x) (groupbykey (cdr x)))) 
  (groupbykey (mapcar '(lambda (x) (apply 'append x)) (GroupBy2 (SplitByTf '(lambda (x) (wcmatch x "SubGroup #*")) In_List))))
)

Marc'Antonio Alessi

  • Swamp Rat
  • Posts: 776
  • Marco
Re: Puzzle: flat list to nested indexed list
« Reply #8 on: December 09, 2017, 06:26:41 am »

Works, for the last in_list that Marco provided - which is list of lists of strings.
The very first (original) one in_list which is list of strings, should be processed a bit...
...with the subfunctions you wrote and that example you provided!  ;D
Y
ou're right, I've corrected the first list that was missing parenthesis-
[/size][/color]
Thank you.
Marc'Antonio Alessi http://alessi.xoom.it//alessi/  Coding manual: http://tinyurl.com/zza7ega

ribarm

  • Water Moccasin
  • Posts: 1710
  • Marko Ribar, architect
Re: Puzzle: flat list to nested indexed list
« Reply #9 on: December 09, 2017, 09:36:20 am »
Just a thought, maybe something like this (foo lst) subroutine...

Code - Auto/Visual Lisp: [Select]
  1. (defun groupbykey ( lst / tmp rtn )
  2.  (foreach itm (reverse lst)
  3.    (if (setq tmp (assoc (car itm) rtn))
  4.      (setq rtn (subst (vl-list* (car itm) (cdr itm) (cdr tmp)) tmp rtn))
  5.      (setq rtn (cons (list (car itm) (cdr itm)) rtn))
  6.    )
  7.  )
  8.  rtn
  9. )
  10.  
  11. ;; (setq l '((0 1 2) (1 2 3) (2 3 4)))
  12. ;; (groupbykey l) => ((0 (1 2)) (1 (2 3)) (2 (3 4)))
  13.  
  14. ;; (setq l '((0 1 2 3) (0 1 2 3 4) (0 1 2 3 4 5)))
  15. ;; (groupbykey l) => ((0 (1 2 3) (1 2 3 4) (1 2 3 4 5)))
  16.  
  17. ;; (setq l '((0 1 2 3) (0 1 2 3 4) (0 1 2 3 4 5)))
  18. ;; (mapcar '(lambda ( x ) (cons (car x) (groupbykey (cdr x)))) (groupbykey l)) => ((0 (1 (2 3) (2 3 4) (2 3 4 5))))
  19.  
  20. (defun foo ( lst )
  21.  (if (and (setq lst (vl-remove 'nil lst)) (vl-every '(lambda ( x ) (assoc (caar lst) (list x))) lst))
  22.    (list (cons (caar lst) (foo (mapcar 'cdr lst))))
  23.  )
  24. )
  25.  
  26. ;; (mapcar '(lambda ( a ) (cons (car a) (groupbykey (cdr a)))) (cddr (mapcar '(lambda ( b ) (cons (car b) (groupbykey (cdr b)))) (cdr (mapcar '(lambda ( c ) (cons (car c) (groupbykey (cdr c)))) (groupbykey l)))))) => nil
  27. ;; (foo l) => ((0 (1 (2 (3 (4 (5)))))))
  28.  
Marko Ribar, d.i.a. (graduated engineer of architecture)

:)

M.R. on Youtube

Marc'Antonio Alessi

  • Swamp Rat
  • Posts: 776
  • Marco
Re: Puzzle: flat list to nested indexed list
« Reply #10 on: December 09, 2017, 09:51:57 am »

Code: [Select]
This is a sample very rudimentary to get a nested indexed list from a flat list (and write to a file).
In_List  > length 27 - the contents of each line can be anything - there are not key in the list, the sample is only to test the results
Out_List > 3 level each level is length 3 >>>> In_List is with the same structure but "linear" or "flat"
Code: [Select]
(defun test (In_List / FilPnt)
    (setq FilLsp "C:\\Temp\\Group6Info.lsp")           
      (setq FilPnt (open FilLsp "w")  Cur_SG 0  Cur_CL 0  Cur_SC 0)
      (write-line "(setq #Group6Info '(" FilPnt)             
      (foreach ForItm In_List
        (cond
          ( (and (= Cur_CL 0) (= Cur_SC 0)) 
            (princ "\n(" FilPnt)  (princ Cur_SG FilPnt) (prin1 (car   ForItm) FilPnt)
            (princ "\n(" FilPnt)  (princ Cur_CL FilPnt) (prin1 (cadr  ForItm) FilPnt)
            (princ "\n(" FilPnt)  (princ Cur_SC FilPnt) (prin1 (caddr ForItm) FilPnt)
               (prin1 (nth 3 ForItm) FilPnt) (prin1 (nth 4 ForItm) FilPnt) (prin1 (nth 5 ForItm) FilPnt)
            (princ ")" FilPnt)
            (setq Cur_SC (1+ Cur_SC))
          )
          ( (= Cur_SC 0)
            (princ "\n(" FilPnt)  (princ Cur_CL FilPnt) (prin1 (cadr  ForItm) FilPnt)
            (princ "\n(" FilPnt)  (princ Cur_SC FilPnt) (prin1 (caddr ForItm) FilPnt)
               (prin1 (nth 3 ForItm) FilPnt) (prin1 (nth 4 ForItm) FilPnt) (prin1 (nth 5 ForItm) FilPnt)
            (princ ")" FilPnt)
            (setq Cur_SC (1+ Cur_SC))
          )
          ( (and (= Cur_CL 2) (= Cur_SC 2))
            (princ "\n(" FilPnt)  (princ Cur_SC FilPnt) (prin1 (caddr ForItm) FilPnt)
               (prin1 (nth 3 ForItm) FilPnt) (prin1 (nth 4 ForItm) FilPnt) (prin1 (nth 5 ForItm) FilPnt)
            (princ ")" FilPnt)
            (princ "\n))" FilPnt)
            (setq Cur_SG (1+ Cur_SG)  Cur_CL 0  Cur_SC 0)
          )
          ( (= Cur_SC 2)
            (princ "\n(" FilPnt) (prin1 Cur_SC FilPnt) (prin1 (caddr ForItm) FilPnt)
              (prin1 (nth 3 ForItm) FilPnt)  (prin1 (nth 4 ForItm) FilPnt)  (prin1 (nth 5 ForItm)  FilPnt)
            (princ "))" FilPnt)
            (setq Cur_CL (1+ Cur_CL)  Cur_SC 0)
          )
          ( T
               (princ "\n(" FilPnt) (prin1 Cur_SC FilPnt) (prin1 (caddr ForItm) FilPnt)
               (prin1 (nth 3 ForItm) FilPnt)  (prin1 (nth 4 ForItm) FilPnt)(prin1 (nth 5 ForItm) FilPnt) (princ ")" FilPnt)
               (setq Cur_SC (1+ Cur_SC))
          )
        )
      )
      (write-line "))" FilPnt)
      (close FilPnt)
)
(setq In_List '(
("SubGroup 0" "Class 00" "SubClass 000" "000 DescriptionA" "000 DescriptionB" "000 Measure")
("SubGroup 0" "Class 00" "SubClass 001" "001 DescriptionA" "001 DescriptionB" "001 Measure")
("SubGroup 0" "Class 00" "SubClass 002" "002 DescriptionA" "002 DescriptionB" "002 Measure")
("SubGroup 0" "Class 01" "SubClass 010" "010 DescriptionA" "010 DescriptionB" "010 Measure")
("SubGroup 0" "Class 01" "SubClass 011" "011 DescriptionA" "011 DescriptionB" "011 Measure")
("SubGroup 0" "Class 01" "SubClass 012" "012 DescriptionA" "012 DescriptionB" "012 Measure")
("SubGroup 0" "Class 02" "SubClass 020" "020 DescriptionA" "020 DescriptionB" "020 Measure")
("SubGroup 0" "Class 02" "SubClass 021" "021 DescriptionA" "021 DescriptionB" "021 Measure")
("SubGroup 0" "Class 02" "SubClass 022" "022 DescriptionA" "022 DescriptionB" "022 Measure")
("SubGroup 1" "Class 10" "SubClass 100" "100 DescriptionA" "100 DescriptionB" "100 Measure")
("SubGroup 1" "Class 10" "SubClass 101" "101 DescriptionA" "101 DescriptionB" "101 Measure")
("SubGroup 1" "Class 10" "SubClass 102" "102 DescriptionA" "102 DescriptionB" "102 Measure")
("SubGroup 1" "Class 11" "SubClass 110" "110 DescriptionA" "110 DescriptionB" "110 Measure")
("SubGroup 1" "Class 11" "SubClass 111" "111 DescriptionA" "111 DescriptionB" "111 Measure")
("SubGroup 1" "Class 11" "SubClass 112" "112 DescriptionA" "112 DescriptionB" "112 Measure")
("SubGroup 1" "Class 12" "SubClass 120" "120 DescriptionA" "120 DescriptionB" "120 Measure")
("SubGroup 1" "Class 12" "SubClass 121" "121 DescriptionA" "121 DescriptionB" "121 Measure")
("SubGroup 1" "Class 12" "SubClass 122" "122 DescriptionA" "122 DescriptionB" "122 Measure")
("SubGroup 2" "Class 20" "SubClass 200" "200 DescriptionA" "200 DescriptionB" "200 Measure")
("SubGroup 2" "Class 20" "SubClass 201" "201 DescriptionA" "201 DescriptionB" "201 Measure")
("SubGroup 2" "Class 20" "SubClass 202" "202 DescriptionA" "202 DescriptionB" "202 Measure")
("SubGroup 2" "Class 21" "SubClass 210" "210 DescriptionA" "210 DescriptionB" "210 Measure")
("SubGroup 2" "Class 21" "SubClass 211" "211 DescriptionA" "211 DescriptionB" "211 Measure")
("SubGroup 2" "Class 21" "SubClass 212" "212 DescriptionA" "212 DescriptionB" "212 Measure")
("SubGroup 2" "Class 22" "SubClass 220" "220 DescriptionA" "220 DescriptionB" "220 Measure")
("SubGroup 2" "Class 22" "SubClass 221" "221 DescriptionA" "221 DescriptionB" "221 Measure")
("SubGroup 2" "Class 22" "SubClass 222" "222 DescriptionA" "222 DescriptionB" "222 Measure")
))
(test In_List)
(setq #Group6Info '(
(0"SubGroup 0"
  (0"Class 00"
   (0"SubClass 000""000 DescriptionA""000 DescriptionB""000 Measure")
   (1"SubClass 001""001 DescriptionA""001 DescriptionB""001 Measure")
   (2"SubClass 002""002 DescriptionA""002 DescriptionB""002 Measure"))
  (1"Class 01"
   (0"SubClass 010""010 DescriptionA""010 DescriptionB""010 Measure")
   (1"SubClass 011""011 DescriptionA""011 DescriptionB""011 Measure")
   (2"SubClass 012""012 DescriptionA""012 DescriptionB""012 Measure"))
  (2"Class 02"
   (0"SubClass 020""020 DescriptionA""020 DescriptionB""020 Measure")
   (1"SubClass 021""021 DescriptionA""021 DescriptionB""021 Measure")
   (2"SubClass 022""022 DescriptionA""022 DescriptionB""022 Measure")
))
(1"SubGroup 1"
  (0"Class 10"
   (0"SubClass 100""100 DescriptionA""100 DescriptionB""100 Measure")
   (1"SubClass 101""101 DescriptionA""101 DescriptionB""101 Measure")
   (2"SubClass 102""102 DescriptionA""102 DescriptionB""102 Measure"))
  (1"Class 11"
   (0"SubClass 110""110 DescriptionA""110 DescriptionB""110 Measure")
   (1"SubClass 111""111 DescriptionA""111 DescriptionB""111 Measure")
   (2"SubClass 112""112 DescriptionA""112 DescriptionB""112 Measure"))
  (2"Class 12"
   (0"SubClass 120""120 DescriptionA""120 DescriptionB""120 Measure")
   (1"SubClass 121""121 DescriptionA""121 DescriptionB""121 Measure")
   (2"SubClass 122""122 DescriptionA""122 DescriptionB""122 Measure")
))
(2"SubGroup 2"
  (0"Class 20"
   (0"SubClass 200""200 DescriptionA""200 DescriptionB""200 Measure")
   (1"SubClass 201""201 DescriptionA""201 DescriptionB""201 Measure")
   (2"SubClass 202""202 DescriptionA""202 DescriptionB""202 Measure"))
  (1"Class 21"
   (0"SubClass 210""210 DescriptionA""210 DescriptionB""210 Measure")
   (1"SubClass 211""211 DescriptionA""211 DescriptionB""211 Measure")
   (2"SubClass 212""212 DescriptionA""212 DescriptionB""212 Measure"))
  (2"Class 22"
   (0"SubClass 220""220 DescriptionA""220 DescriptionB""220 Measure")
   (1"SubClass 221""221 DescriptionA""221 DescriptionB""221 Measure")
   (2"SubClass 222""222 DescriptionA""222 DescriptionB""222 Measure")
))))
Code: [Select]
Comando: (caddr (DXF 1 (cdr (DXF 1 (cdr (DXF 1 #Group6Info))))))
"111 DescriptionB"
Comando: (setq Pfx_SG 1   Pfx_CL 2   Pfx_SC 0)
0
Comando: (DXF Pfx_SG #Group6Info)
("SubGroup 1" (0 "Class 10" (0 "SubClass 100" "100 DescriptionA" "100 DescriptionB" "100 Measure") (1 "SubClass 101" "101 DescriptionA" "101 DescriptionB" "101 Measure") (2 "SubClass 102" "102 DescriptionA" "102 DescriptionB" "102 Measure")) (1 "Class 11" (0 "SubClass 110" "110 DescriptionA" "110 DescriptionB" "110 Measure") (1 "SubClass 111" "111 DescriptionA" "111 DescriptionB" "111 Measure") (2 "SubClass 112" "112 DescriptionA" "112 DescriptionB" "112 Measure")) (2 "Class 12" (0 "SubClass 120" "120 DescriptionA" "120 DescriptionB" "120 Measure") (1 "SubClass 121" "121 DescriptionA" "121 DescriptionB" "121 Measure") (2 "SubClass 122" "122 DescriptionA" "122 DescriptionB" "122 Measure")))

Comando: (car (DXF Pfx_CL (cdr (DXF Pfx_SG #Group6Info))))

"Class 12"
Comando: (car (DXF Pfx_SC (cdr (DXF Pfx_CL (cdr (DXF Pfx_SG #Group6Info))))))
"SubClass 120"
« Last Edit: December 09, 2017, 09:57:43 am by Marc'Antonio Alessi »
Marc'Antonio Alessi http://alessi.xoom.it//alessi/  Coding manual: http://tinyurl.com/zza7ega

Marc'Antonio Alessi

  • Swamp Rat
  • Posts: 776
  • Marco
Re: Puzzle: flat list to nested indexed list
« Reply #11 on: December 09, 2017, 10:16:03 am »
this is the final use
Marc'Antonio Alessi http://alessi.xoom.it//alessi/  Coding manual: http://tinyurl.com/zza7ega

Lee Mac

  • Seagull
  • Posts: 11854
  • AutoCAD 2015 Windows 7 London, England
Re: Puzzle: flat list to nested indexed list
« Reply #12 on: December 09, 2017, 10:26:08 am »
Nice one Marc!

Perhaps this can help with the implementation?
Or have you specifically opted for edit box tiles such that the user may edit the stored values?

Marc'Antonio Alessi

  • Swamp Rat
  • Posts: 776
  • Marco
Re: Puzzle: flat list to nested indexed list
« Reply #13 on: December 09, 2017, 11:01:32 am »
Thanks Lee it was just the example I was looking for!  :smitten: 
Code: [Select]
> Or have you specifically opted for edit box tiles such that the user may edit the stored values?
Yes, this serves to capture the normalized descriptions with the possibility of completing them and bringing them
 back to the title-block and also placing the prefix of belonging. The information comes from an Excel file where I
 can see the informations even in a "3D" sheet (see my e-book and image)
[/code]
« Last Edit: December 09, 2017, 11:09:04 am by Marc'Antonio Alessi »
Marc'Antonio Alessi http://alessi.xoom.it//alessi/  Coding manual: http://tinyurl.com/zza7ega

Grrr1337

  • Bull Frog
  • Posts: 453
Re: Puzzle: flat list to nested indexed list
« Reply #14 on: December 09, 2017, 11:20:22 am »
Thanks for sharing the usage idea, Marc!
I always appreciate such thing.