Thread: comparing lists

    #1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2003
    Posts
    96
    Rep Power
    12

    comparing lists


    I guess what I am looking for is an associative array type function. I want to have similar to the following:

    list 1) a b d f h k
    list 2) a->1 b->2 c->3 d->4....etc

    then have the list come out like

    1 2 4 6 8 11

    then be able to imput a list like 1 and have the extra info from list 2 come out the other end. I don't even know if python is the best way to do this, any method would be great, but I think I would like to do it in python or excel, or something that didn't require buying another programming language, that is basically all it needs to do.

    Any suggestions
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Intermediate (1500 - 1999 posts)

    Join Date
    Feb 2004
    Location
    Lawrence, Kansas [KU]
    Posts
    1,559
    Rep Power
    15
    you want a python dictionary:

    Code:
    >>> d = {'a':1,'b':2,'c':3,'d':4}                           
    >>> b = ['a','c','b']
    >>> for a in b: print d[a]
    ... 
    1
    3
    2
    for more on dictionaries:
    http://diveintopython.org/native_dat...dbchelper.dict
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2004
    Location
    Germany
    Posts
    11
    Rep Power
    0
  6. #4
  7. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2004
    Posts
    461
    Rep Power
    25
    also if you are wanting to join a list into a single string you can do this

    Code:
    daList = ['h', 'e', 'y']
    combined = join(daList)
    print combined
  8. #5
  9. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2004
    Posts
    394
    Rep Power
    52
    Hi!

    @CyBerHigh: Maybe a typo, should be
    Code:
    combined = ''.join(daList)

    Regards, mawe

IMN logo majestic logo threadwatch logo seochat tools logo