Python Subtract integers in List to return a value -


i take large file in python 2.7:

123 456 gthgggth 223 567 fgrthsys 12933 4656832 gjwsoooskkssj ..... 

and want read in file line line, disregard third element, , subtract second element in each line first element. line 1 above return 333.

i have tried far:

def deletelast(list):           newl = list.pop()             return newl  f = open(file_name, 'r') line = f.readline() while line:     l = line.split()     l2 = deletelast(l)     l3 = [int(number) number in l2]     length = l3[1]-l3[0]     print length f.close() 

but, when try compiler says:

 valueerror: invalid literal int() base 10: 't' 

all appreciated.

that because list.pop() returning "popped off" item, doesn't return list again.

instead of deletelast function have written, better use slice this:

l2 = line.split()[0:2]

you going run problem later because while loop isn't advancing @ all. consider using loop instead.


Comments

Popular posts from this blog

c++ - llvm function pass ReplaceInstWithInst malloc -

Cross-Compiling Linux Kernel for Raspberry Pi - ${CCPREFIX}gcc -v does not work -

java.lang.NoClassDefFoundError When Creating New Android Project -