pulling data from a list with mapcar

Discussion in 'AutoCAD' started by kemp, Apr 10, 2004.

  1. kemp

    kemp Guest

    I have a list of lists and I want to pull out all of the 7th embedded list
    entries to make one list. Is there a way to do this with mapcar? I am
    already using it to pull the first entries like this:
    (mapcar 'car data-list)
    and the second like this:
    (mapcar 'cdr data-list)
    etc. I might be able to use a foreach statement with nth 7 or something but
    i want to play with mapcar :)

    thanks,
    kemp
     
    kemp, Apr 10, 2004
    #1
  2. If you are saying your original data is ...

    (setq lst
    '(
    ("1" "2" "3" "4" "5" "6" "7" "8")
    ("1" "2" "3" "4" "5" "6" "7" "8")
    ("1" "2" "3" "4" "5" "6" "7" "8")
    )
    )

    (mapcar
    '(lambda (x) (nth 6 x))
    lst
    )

    Should do it.
     
    michael puckett, Apr 10, 2004
    #2
  3. kemp

    kemp Guest

    Nice - exactly what I wanted. I tried something similar but the way I tried
    to format the lambda was all screwed up, now that I can see how it's really
    done I should be good.

    Thanks a bunch Michael.

    kemp
     
    kemp, Apr 10, 2004
    #3
  4. You're very welcome :)

    Supper's ready, Woo hoo, gotta go!
     
    michael puckett, Apr 10, 2004
    #4
Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.