Python: Deleting a list element based on elements from another list
Question: I have two lists here. I am shuffling list `i`, checking it's first element
and then deleting the corresponding element from list `j` e.g. if after a
shuffle, `i[0] == 3`, then i want to delete element 3 from list '`j`'.

    
    
    i = ['a','b','c','d','e','f','g','h']
    random.shuffle(i)
    
    j = [1,2,3,4,5,6,7,8]
    
    if i[0] == 'a':
        del j[0]
    elif i[0] == 'b':
        del j[1]
    elif i[0] == 'c':
        del j[2]
    elif i[0] == 'd':
        del j[3]
    elif i[0] == 'e':
        del j[4]
    elif i[0] == 'f':
        del j[5]
    elif i[0] == 'g':
        del j[6]
    elif i[0] == 'h':
        del j[7]
    

Is there a way to do this task without listing out if statements like this? As
it stands, if `i[0] == 6`, then several if statements need to be checked which
is a waste of processing power, in principle.

Thanks, Steve


Answer: You can do

    
    
    j.remove(i[0])
    

To remove element with value i[0] from list j.

[Edit] Updated:

    
    
    import random
    
    i = ['a','b','c','d','e','f','g','h']
    k=i[:]
    
    random.shuffle(i)
    
    print i
    print k
    print j
    
    j = [1,2,3,4,5,6,7,8]
    print i[0]
    print k.index(i[0])
    del j[k.index(i[0])]
    print j
    

