Announcement

Collapse
No announcement yet.

Comparing Lists

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Comparing Lists

    Hi would just like to ask what is the best way to compare 4
    lists of names and only be left with the names that show up
    in more than 1 of the lists, so for the example below i have 4
    lists of names and peter only shows up in 1 so he should not
    make it in to the final list, but the rest show up in more
    than 1 list so will make it in.

    The list of names would be stored in arrays list1$(), list2$()
    list3$(), list4$(), and list5$() being the new list created by
    the prossess of the 4 lists.

    Example

    list 1
    ------
    scott
    heather
    john
    trevor
    gail

    list 2
    ------
    scott
    heather
    adam
    john
    trevor
    gail

    list 3
    ------
    scott
    heather
    adam
    trevor
    gail

    list 4
    ------
    scott
    heather
    adam
    peter
    john
    trevor
    gail

    list 5 (output)
    ------
    scott
    heather
    adam
    john
    trevor
    gail


    guess am looking for the simplest way to do this with out
    writing pages of code if thats possible.

    Using PB 3.5

    Thanks.


    ------------------
    -Scott
    -Scott

  • #2
    If the lists aren't too long (= if memory isn't a problem), you could simply:
    - add all the names from the 4 lists on a new temp list
    - sort the temp list
    - follow the temp list from the first element and count how many times a name is repeated; if count > 1 then add that name to the 5th list

    Bye!

    ------------------
    Try TrID file identifier! Over 1040 filetypes and counting...
    Give a powerfull scriptable Lua interface to your application with PowerBLua
    PBTracer - Tracer / Profiler for PowerBASIC (soon!)


    [This message has been edited by Marco Pontello (edited April 26, 2004).]
    -- The universe tends toward maximum irony. Don't push it.

    File Extension Seeker - Metasearch engine for file extensions / file types
    Online TrID file identifier | TrIDLib - Identify thousands of file formats

    Comment


    • #3
      i really should 'rename' this so it shows up with 'search' because it shows 'generic' list comparisons..

      win32: find differences in win32api.inc and other text files april 21, 2000

      that's pb/cc code but it should give you an idea how to do it under ms-dos.

      if anyone has a good idea for a 'subject' line for above drop me a note and i'll re-post it and ask the webmaster to delete the original (as i understand it there is no maintenance allowed on the subject so you have to delete and re-enter).

      mcm
      mailto:[email protected][email protected]</a>

      Michael Mattias
      Tal Systems (retired)
      Port Washington WI USA
      [email protected]
      http://www.talsystems.com

      Comment

      Working...
      X