See the top rated post in this thread. Click here

Page 1 of 3 123 LastLast
Results 1 to 10 of 27

Thread: Lists within lists - simplify

  1. #1
    All AUGI, all the time
    Join Date
    2015-10
    Location
    Belgrade, Serbia, Europe
    Posts
    564
    Login to Give a bone
    0

    Default Lists within lists - simplify

    Is there any more efficant way to convert list of type :

    ((1 2 3) (2 3 4) ((5 7 3)) (((G))) ((((A)))))
    to list
    (1 2 3 2 3 4 5 7 3 G A)

    I've managed to do this only to this level
    ((1 2 3) (2 3 4) ((5 7 3)))
    but I want for all levels of brackets...

    Here is my code :
    Code:
    (defun lstnlst1 (lst / lstn)
    (foreach el lst
    (if (= (listp el) nil)
    (setq lstn (cons el lstn))
    (progn
    (foreach ee el
    (if (= (listp ee) nil)
    (setq lstn (cons ee lstn))
    (progn
    (foreach e ee
    (if (= (listp e) nil)
    (setq lstn (cons e lstn))
    )))
    )))
    ))
    (setq lstn (reverse lstn))
    )
    M.R.

  2. #2
    All AUGI, all the time
    Join Date
    2010-10
    Posts
    535
    Login to Give a bone
    0

    Default Re: Lists within lists - simplify

    try this

    Code:
    (defun SimplifyList (lst / looplst a b c y newlst )
    (defun looplst (l)
          	(if (listp (setq y (car l)))
          		(looplst  y) l) 
                )      
          (while (setq a (car lst))
                 (setq b (cdr lst))
                 (setq c (looplst a))
                	(foreach x c
                          	(setq newlst (cons x newlst)))
                (setq lst b)
                )
          (reverse newlst)
          )
    Code:
    (setq yourlist '((1 2 3) (2 3 4) ((5 7 3)) (((G))) ((((A))))))
    (simplifylist yourlist)
    (1 2 3 2 3 4 5 7 3 G A)
    Last edited by pbejse; 2011-05-04 at 05:28 AM.

  3. #3
    All AUGI, all the time
    Join Date
    2015-10
    Location
    Belgrade, Serbia, Europe
    Posts
    564
    Login to Give a bone
    0

    Default Re: Lists within lists - simplify

    You didn't understand question... I want simplification of all possible combinations of lists with many sublists with many brackets...

    Command: (setq lst '(((( 1 3 6) (((((6 9 4))))) ))) )
    ((((1 3 6) (((((6 9 4))))))))

    Command: (simplifylist lst)
    (1 3 6)
    As you can see I get only first part of this new list type...

    Any ideas...

    M.R.

  4. #4
    All AUGI, all the time
    Join Date
    2010-10
    Posts
    535
    Login to Give a bone
    1

    Default Re: Lists within lists - simplify

    Funny how you post a example of your list then give another format afterwards

    But it does work on the first list condition right?

    Now, a long time ago i;'ve was playing around with recursion for nested list such as yours, I noticed that
    there are too many variations,

    So i came up with just one routine no matter how nested the list is

    Code:
    (defun ConvertList  (lst)
          (read (strcat "("
                        (vl-list->string
                              (vl-remove-if
                                    '(lambda (x)
                                           (or
                                                 (= x 40)
                                                 (= x 41)))
                                    (vl-string->list
                                          (vl-princ-to-string lst))))
                        ")")
                )
          )

    Hope this one helps,

  5. #5
    All AUGI, all the time
    Join Date
    2015-10
    Location
    Belgrade, Serbia, Europe
    Posts
    564
    Login to Give a bone
    0

    Default Re: Lists within lists - simplify

    That's it, you did it...

    Thanks, pbejse
    (nice idea to convert list to string and then remove all brackets with vl-remove-if and lambda)
    This is real programming solution, I would give you an accolade if I could...
    Thanks again...



  6. #6
    All AUGI, all the time
    Join Date
    2010-10
    Posts
    535
    Login to Give a bone
    1

    Default Re: Lists within lists - simplify

    Glad it works for you M.R.

    Cheers

  7. #7
    100 Club
    Join Date
    2003-11
    Location
    Dublin, Ireland.
    Posts
    152
    Login to Give a bone
    0

    Default Re: Lists within lists - simplify

    Brilliant.

  8. #8
    AUGI Addict
    Join Date
    2008-02
    Posts
    1,141
    Login to Give a bone
    1

    Default Re: Lists within lists - simplify

    Code:
    (defun AT:ListCondense (lst)
      ;; Condense list of sublists to a single list
      ;; lst - list of lists to process
      ;; Alan J. Thompson, 08.10.10
      (if lst
        (if (listp lst)
          (append (AT:ListCondense (car lst)) (AT:ListCondense (cdr lst)))
          (list lst)
        )
      )
    )
    Last edited by alanjt; 2011-05-05 at 01:38 PM.

  9. #9
    100 Club
    Join Date
    2003-11
    Location
    Dublin, Ireland.
    Posts
    152
    Login to Give a bone
    0

    Default Re: Lists within lists - simplify

    NIce one Alan.

    Are you using the function within itself here???
    If you have the time, could you explain what you are doing?

    Cheers

  10. #10
    AUGI Addict
    Join Date
    2008-02
    Posts
    1,141
    Login to Give a bone
    0

    Default Re: Lists within lists - simplify

    Quote Originally Posted by jmcshane View Post
    NIce one Alan.

    Are you using the function within itself here???
    If you have the time, could you explain what you are doing?

    Cheers
    Yes, it's recursive.
    When I get a chance, I'll talk you through it.

Page 1 of 3 123 LastLast

Similar Threads

  1. Drawing Lists
    By timsea81 in forum Revit MEP - General
    Replies: 10
    Last Post: 2010-01-07, 10:01 PM
  2. Drawing Lists
    By david.delcher in forum Revit Architecture - General
    Replies: 26
    Last Post: 2006-10-24, 04:54 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •