Hi,
I have a list of lists taken from a text file.
I would like to add the elements that are in the second and third position,but these are not simple elements, but represent the position of another element that is found in the sublist.
For example:
RavCoder
I have a list of lists taken from a text file.
I would like to add the elements that are in the second and third position,but these are not simple elements, but represent the position of another element that is found in the sublist.
For example:
list = [1,0,0,3] list[1] = 0 list[2] = 0 sum = 1 + 1 --> 2 # because zero corresponds to position 0 which has as its element 1Then the value I got must go to the third position, because the element 3 always represents the index,where you will have to put the new item.
list = [1 , 0, 0, 2]This is my code for now....
#Convert text in a list #def split_four(x): file = open('data.txt') lines = file.read().split(',') #print(lines) #split into sublist with four items n = 4 m = 1 split_four = [lines[i:i+n] for i in range(0,len(lines), n-m)] #print(split_four) for x in split_four: for y in range (0 ,len(x)): # sum index = elementThanks and regards,
RavCoder