Jump to content

[noob ques] python help

Go to solution Solved by fizzlesticks,

 

guys i need help here it says index error but i think index of the list is just fine !

def original_lst(L):    lst = [1,2,2,3,4,9,9]    count = 0    i = len(lst)    m = len(lst)-1    while i > 0:        if lst[i] == lst[m]:           del lst[i]        i -= 1        m -= 1        

The maximum index of a list is the length - 1.

guys i need help here it says index error but i think index of the list is just fine !

def original_lst(L):    lst = [1,2,2,3,4,9,9]    count = 0    i = len(lst)    m = len(lst)-1    while i > 0:        if lst[i] == lst[m]:           del lst[i]        i -= 1        m -= 1        

CPU: FX8320 @ 4.2GHZ, GPU: R9 390 PCS+Cooler: Hyper 212 Evo, MotherBoard: ASRock 970 Extreme 3 r2.0, PowerSupply: EVGA 600b 80+Bronze, Storage: seagate Barracuda 1TB SSHD & Case: Corsair Carbide 200r

Link to comment
https://linustechtips.com/topic/248252-noob-ques-python-help/
Share on other sites

Link to post
Share on other sites

 

guys i need help here it says index error but i think index of the list is just fine !

def original_lst(L):    lst = [1,2,2,3,4,9,9]    count = 0    i = len(lst)    m = len(lst)-1    while i > 0:        if lst[i] == lst[m]:           del lst[i]        i -= 1        m -= 1        

The maximum index of a list is the length - 1.

1474412270.2748842

Link to comment
https://linustechtips.com/topic/248252-noob-ques-python-help/#findComment-3405004
Share on other sites

Link to post
Share on other sites

The maximum index of a list is the length - 1.

it fixed it but can u explain why is the max length is leng-1 ?

CPU: FX8320 @ 4.2GHZ, GPU: R9 390 PCS+Cooler: Hyper 212 Evo, MotherBoard: ASRock 970 Extreme 3 r2.0, PowerSupply: EVGA 600b 80+Bronze, Storage: seagate Barracuda 1TB SSHD & Case: Corsair Carbide 200r

Link to comment
https://linustechtips.com/topic/248252-noob-ques-python-help/#findComment-3405112
Share on other sites

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×