Matthew Pearson Matthew Pearson - 1 year ago 77
Python Question

del x[n] not working

I have a list and I am trying to remove the first item in it

I have tried to use this code, but it doesn't do anything

del rows[rows.index(userInfo)][9].split()[0]

for context


finds an item in a list which is a string then splits the string into a list, this string is

Skyfall Skyfall DarkKnight DieHard CaptainAmerica Deadpool TheMatrix CaptainAmerica TheMatrix CaptainAmerica TheBourneIdentity

Answer Source

You can use pop() or index it out with slicing like this:

rows[rows.index(userInfo)][9] = " ".join(rows[rows.index(userInfo)][9].split().pop())


rows[rows.index(userInfo)][9] = " ".join(rows[rows.index(userInfo)][9].split()[1:])
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download