Author Topic: what is the shorter way  (Read 836 times)

0 Members and 1 Guest are viewing this topic.

Andrea

  • Water Moccasin
  • Posts: 2372
what is the shorter way
« on: August 05, 2005, 09:41:29 AM »
what is the shorter way to do this...

I have a list...

(setq list1(list "item1" "item1" "item4" "item1" "item4" "item5" "item5" "item8"))

(setq list2(list "item1a" "item1a" "item4a" "item1a" "item4b" "item5b" "item5b" "item8a"))

now I need to know, how many item of each I have...
eg:

3  item1 for item1a
1  item4 for item4a
1  item4 for item4b
2  item5 for item5b
1  item8 for item8a

see ?

for the moment, i have made a (foreach..    and appen each same item in a list...and export all this to a temporary txt file

but not sure if there is a function doing that..


thanks.
Keep smile...

daron

  • Guest
what is the shorter way
« Reply #1 on: August 05, 2005, 09:48:44 AM »
(setq lst1 (list ("item1" "item1" "item4" "item1" "item4" "item5" "item5" "item8")))
(length lst1)

returns: 8

Moving thread to proper forum.

Andrea

  • Water Moccasin
  • Posts: 2372
what is the shorter way
« Reply #2 on: August 05, 2005, 10:10:38 AM »
Quote from: daron
(setq lst1 (list ("item1" "item1" "item4" "item1" "item4" "item5" "item5" "item8")))
(length lst1)

returns: 8

Moving thread to proper forum.


thanks Daron....I know that...but need to specify...

Quote from: daron

how many item of each I have
Keep smile...

Crank

  • Swamp Rat
  • Posts: 1443
what is the shorter way
« Reply #3 on: August 05, 2005, 10:33:34 AM »
If I understand you right, you first want to compare every nth member of list1 with the nth member of list2. Every different combination is counted seperately.

A temporary txt file seems slow to me. Why not keep the result in memory?

I can imagine that you want a result like:
Code: [Select]

'((3 . "item1")(1 . "item4")(1 . "item4")(2 . "item5")(1 . "item8"))

 Vault Professional 2018     /      Building Design Suite Ultimate 2017     /     AEC Collection 2018 + 2019 +2020

Andrea

  • Water Moccasin
  • Posts: 2372
what is the shorter way
« Reply #4 on: August 09, 2005, 12:30:01 PM »
Crank,

Yes this is good..
don't use nth very often...

but thanks..

In fact i allready created mine, without exporting to a txt file but allow user to do-it.

 :wink:
Keep smile...