Advertisement
OverSkillers

ExameRecurso20162017_ex5

Jan 9th, 2018
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.86 KB | None | 0 0
  1. import operator
  2.  
  3. def exame1617_5():
  4.     fich = open('input.txt','r+')
  5.     fich2 = open('input2.txt','w')
  6.     lista = []
  7.     for line in fich.readlines():
  8.         palavra = line.strip().split(' ')
  9.         lista.append(palavra)
  10.    
  11.     for i in range(len(lista)):
  12.         numero = lista[i][2]
  13.         numeros = numero.strip().split(':')
  14.         valor = int(numeros[0])*60*60 + int(numeros[1])* 60 + int(numeros[2])
  15.         lista[i][2] = valor
  16.     lista2 = sorted(lista,key = operator.itemgetter(2),reverse = False)
  17.  
  18.     for i in range(5):
  19.         if i == 0:
  20.             string = lista2[i][0] + ' ' + lista2[i][1] + ' ' + str(lista2[i][2]) + ' \n'
  21.             fich2.write(string)
  22.         else:
  23.             valor = lista2[i][2] - lista2[0][2]
  24.             string = lista2[i][0] + ' ' + lista2[i][1] + ' ' + str(valor) + ' \n'
  25.             fich2.write(string)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement