I am new to python and am trying to access a single specific element in a list of lists. I have tried:
line_list[2][0]
this one isn't right as its a tuple and the list only accepts integers.
line_list[(2, 0)]
line_list[2, 0]
This is probably really obvious but I just can't see it.
def rpd_truncate(map_ref):
#Munipulate string in order to get the reference value
with open (map_ref, "r") as reference:
line_list = []
for line in reference:
word_list = []
word_list.append(line[:-1].split("\t\t"))
line_list.append(word_list)
print line_list[2][0]
I get the exact same as if I used line_list[2]:
['Page_0', '0x00000000', '0x002DF8CD']
line_listcontains so we can help you.line_list[2][0]should work for list of lists, like[[1, 2, 3], [4, 5, 6]]. Are you sure you have list of lists? Are you sure you didn't get 'index out of range' exception?a = [4,5,6] ; b = [a,7,8]; print b[0][2]