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

    Join Date
    Sep 2012
    Posts
    10
    Rep Power
    0

    List.index Is is printable?


    Hello! I was codeing and I stumbled upon a problem.
    I want to change an attribute of one object, within a class.
    These objects are also added to a list, so what I do when i want to change them is to do that using the objects index number.

    THE QUESTION: Is there anyway to print the index number of every object in the list?

    I know i can write it like - print (testlist.index(object))
    But that is just one of the objects !

    All help is appreciated!
  2. #2
  3. Contributing User
    Devshed Demi-God (4500 - 4999 posts)

    Join Date
    Aug 2011
    Posts
    4,703
    Rep Power
    480
    Code:
    for t in enumerate(LIST):
        print('str(LIST[%d]) == %s'%t)
    Code:
    for i in range(len(LIST)):
        print(i,LIST[i])
    [code]Code tags[/code] are essential for python code and Makefiles!
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2012
    Posts
    10
    Rep Power
    0
    THANK YOU!! much love

IMN logo majestic logo threadwatch logo seochat tools logo