Maybe I am misunderstanding the question, but there are a few different ways to count the number of items in a list.
Maybe sort them (acad_strlsort lstStrings)
Code:
;I would create a sorted list of the members
(duplicatesremove (list "A1" "A1" "A2" "A3" "A2" "A1")) returns '( "A1" "A2" "A3")
; and then count them
(stringscount (list "A1" "A1" "A2" "A3" "A2" "A1")) returns '(("A1" 3) ("A2" 2) ("A3" 1))
Code:
(defun duplicatesremove (lstStrings / lstStrings2)
(foreach strItem lstStrings
(if (not (member strItem lstStrings2))
(setq lstStrings2 (cons strItem lstStrings2))
)
)
(if lstStrings2
(acad_strlsort lstStrings2)
)
)
(defun StringsCount (lstStrings / intCount ilstOfSublists)
(foreach strItem (duplicateremove lstStrings)
(setq intCount (apply '+ (mapcar '(lambda (X)(if (= X strItem) 1 0)) lstStrings)))
(setq lstOfSublists (cons (list strItem intCount) lstOfSublists))
)
(reverse lstOfSublists)
)
or maybe do it this way.
Code:
;I would create a list of sublists
(stringsublists (list "A1" "A1" "A2" "A3" "A2" "A1")) returns '( ("A1" "A1" "A1") ("A2" "A2") ("A3") )
; and then count them
(stringscount2 (list "A1" "A1" "A2" "A3" "A2" "A1")) returns '(("A1" 3) ("A2" 2) ("A3" 1))
Code:
(defun StringSublists (lstStrings / lstOfSublists strItem1 strItem2)
(setq lstStrings (reverse (acad_strlsort lstStrings))
strItem1 (car lstStrings)
lstStrings1 (list strItem1)
)
(foreach strItem2 (cdr lstStrings)
(if (= strItem2 strItem1)
(setq lstStrings1 (cons strItem2 lstStrings1))
(setq lstOfSublists (cons lstStrings1 lstOfSublists)
lstStrings1 (list strItem2)
)
)
(setq strItem1 strItem2)
)
(cons lstStrings1 lstOfSublists)
)
(defun StringsCount2 (lstStrings)
(mapcar '(lambda (X)(list (car X)(length X))) (stringsublists lstStrings))
)