TypeError: 'type' object is not subscriptable

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • sobincc
    New Member
    • Nov 2015
    • 1

    TypeError: 'type' object is not subscriptable

    i have a python code..
    Code:
    thelist = []
    with open('rollernet.txt') as f:
        thelist =[list(map(int,x.split())) for x in f.readlines()]
        
    sorted(thelist, key=lambda line : line[2])
    
    other_list = []
    
    initial_time = int(list[0][2])
    But shows error as
    File "script.py" , line 14, in <module>
    initial_time = int(list[0][2]) #
    TypeError: 'type' object is not subscriptable

    what to do with this
    Last edited by Rabbit; Nov 1 '15, 05:02 PM. Reason: Please use [code] and [/code] tags when posting code or formatted data.
  • dwblas
    Recognized Expert Contributor
    • May 2008
    • 626

    #2
    "list" is a type, like "int". The only thing you have declared in the program is "thelist". Note also that the "sorted" line does nothing. Print thelist to see for yourself and then see the sorted example at http://www.dotnetperls.com/sort-python

    Comment

    Working...