python - Out of index range error, a while loop containing list and dictionary -


after finding alternative solution previous problem, have encountered new one. asked teacher , suggested use dict(zip) in format.

final={} rawlines=open("x.txt").readlines() y=0 while y <5:  line in rawlines:     userlist=rawlines[y].split(',')     userid=userlist[0]     avmph=userlist[1]     print(avmph)     #print(userid)     lines in rawlines[0:]:         lines=lines[:-1]         items=lines.split(',')         final[items[0]]=dict(zip(userid,avmph))  y=y+1 else:  sorted[avmph()]  print(avmph)  print(userid) 

i getting out of index range error line. error message

traceback (most recent call last):   file "c:\users\ryan\desktop\test.py", line 6, in <module>     userlist=rawlines[y].split(',') indexerror: list index out of range 

i have used .txt file in style of .csv file allows me create lists. need sort average miles per hour , return user ids alongside. main problem seems reside 'y' variable , while loop (link screenshot of .txt file)http://gyazo.com/ac8f734b9bb625398de6412191a64981

if write

y=0 while y < 5: print(y); y+=1 

then output be:

0 1 2 3 4 

& file contains 4 lines. rawlines[y], y=4 tries access fifth line of file. gives error. replace fourth line while y < 4 fix it.


Comments

Popular posts from this blog

Payment information shows nothing in one page checkout page magento -

tcpdump - How to check if server received packet (acknowledged) -