Last active
October 11, 2015 17:56
-
-
Save jorgebastida/2622564 to your computer and use it in GitHub Desktop.
enjoydjango - Ejemplo Python
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env python | |
| def leer_fichero(nombre_fichero): | |
| fichero = open(nombre_fichero) | |
| contenido = fichero.read() | |
| fichero.close() | |
| return contenido | |
| # | |
| # Comienzo del programa | |
| # | |
| llamadas = leer_fichero("llamadas.txt") | |
| numeros = {} | |
| total = 0.0 | |
| for linea in llamadas.split("\n"): | |
| campos = linea.split(" ") | |
| numero = campos[0] | |
| importe = float(campos[-1].replace(",", ".")) | |
| # Total de cada número | |
| if numero in numeros: | |
| numeros[numero] += importe | |
| else: | |
| numeros[numero] = importe | |
| # Total de la factura | |
| total += importe | |
| print "Total factura: {} euros.".format(total) | |
| # Calculo del numero que mas gasta | |
| mayor_telefono = '' | |
| mayor_importe = 0.0 | |
| for telefono, importe in numeros.items(): | |
| if importe > mayor_importe: | |
| mayor_telefono = telefono | |
| mayor_importe = importe | |
| print "Mayor gasto: {}, {} euros.".format(mayor_telefono, mayor_importe) | |
| print "Gasto medio por numero: {} euros.".format(total / len(numeros)) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 661661766 MG movistar 18Ene. 08:13 03s 0,1525 | |
| 647664494 N movistar 5Feb. 13:24 17s 0,2207 | |
| 667766944 N Vodafone 18Ene. 23:50 05m 33s 1,5353 | |
| 614769766 N movistar 6Feb. 21:33 15s 0,2124 | |
| 614711616 N Orange 19Ene. 17:55 03m 44s 1,0818 | |
| 944611666 N Vizcaya 8Feb. 12:49 03m 12s 0,9487 | |
| 661661766 MG movistar 21Ene. 22:25 07m 28s 0,5218 | |
| 661661766 MG movistar 9Feb. 10:02 04s 0,1533 | |
| 664666664 N Euskalte 22Ene. 14:18 05m 06s 1,4230 | |
| 661661766 MG movistar 9Feb. 10:04 10m 43s 0,6837 | |
| 667766944 N Vodafone 24Ene. 13:47 06m 09s 1,6850 | |
| 669464644 MG Vodafone 9Feb. 19:44 01m 31s 0,2255 | |
| 669464644 MG Vodafone 27Ene. 14:51 01m 23s 0,2189 | |
| 614717444 N Yoigo 11Feb. 15:55 29s 0,2851 | |
| 944666616 N Vizcaya 28Ene. 19:22 01m 23s 0,4953 | |
| 669464644 MG Vodafone 11Feb. 17:12 46s 0,1882 | |
| 666474764 N Vodafone 29Ene. 21:12 39s 0,3122 | |
| 614717444 N Yoigo 12Feb. 21:37 58s 0,4203 | |
| 679667646 N movistar 29Ene. 21:40 49s 0,3538 | |
| 669494666 N movistar 13Feb. 13:11 03s 0,1625 | |
| 661661766 MG movistar 30Ene. 17:17 17m 37s 1,0273 | |
| 666474761 N Vodafone 15Feb. 11:17 03m 27s 1,0111 | |
| 669464644 MG Vodafone 2Feb. 21:05 02s 0,1517 | |
| 944647664 N Vizcaya 16Feb. 17:14 32s 0,2831 | |
| 669464644 MG Vodafone 2Feb. 23:32 33s 0,1774 | |
| 664666664 Mo Euskaltel 18Ene. 08:13 0,1500 | |
| 664666664 Mo Euskaltel 2Feb. 10:38 0,1500 | |
| 661661766 MG movistar 18Ene. 08:15 0,1000 | |
| 669464644 MG Vodafone 2Feb. 18:52 0,1000 | |
| 646161966 Mo movistar 5Feb. 16:34 0,1500 | |
| 666667644 Mo Vodafone 5Feb. 22:30 0,1500 | |
| 669494666 Mo movistar 21Ene. 18:05 0,1500 | |
| 647664494 Mo movistar 7Feb. 01:35 0,1500 | |
| 664144666 Mo Vodafone 22Ene. 14:25 0,1500 | |
| 641646416 Mo Orange 7Feb. 06:01 0,1500 | |
| 664144666 Mo Vodafone 22Ene. 14:29 0,1500 | |
| 666664164 Mo movistar 7Feb. 16:38 0,1500 | |
| 664144666 Mo Vodafone 22Ene. 18:27 0,1500 | |
| 666661497 Mo Vodafone 8Feb. 15:26 0,1500 | |
| 646161966 Mo movistar 23Ene. 22:39 0,1500 | |
| 664666664 Mo Euskaltel 10Feb. 16:11 0,1500 | |
| 646161966 Mo movistar 23Ene. 23:07 0,1500 | |
| 664666664 Mo Euskaltel 10Feb. 18:50 0,1500 | |
| 614717444 Mo Yoigo 23Ene. 23:17 0,1500 | |
| 661764411 MG movistar 12Feb. 15:16 0,1000 | |
| 641646416 Mo Orange 24Ene. 02:13 0,1500 | |
| 664144666 Mo Vodafone 12Feb. 20:25 0,1500 | |
| 664666664 Mo Euskaltel 24Ene. 20:02 0,1500 | |
| 664144666 Mo Vodafone 12Feb. 20:40 0,1500 | |
| 669464644 MG Vodafone 25Ene. 16:52 0,1000 | |
| 669494666 Mo movistar 13Feb. 13:14 0,1500 | |
| 664666664 Mo Euskaltel 26Ene. 09:20 0,1500 | |
| 666661497 Mo Vodafone 26Ene. 17:01 0,1500 | |
| 669464644 MG Vodafone 14Feb. 18:38 0,1000 | |
| 667664644 Mo Vodafone 27Ene. 17:36 0,1500 | |
| 666474761 Mo Vodafone 15Feb. 10:52 0,1500 | |
| 671764466 MG movistar 29Ene. 08:24 0,1000 | |
| 666664667 Mo Vodafone 15Feb. 12:15 0,1500 | |
| 666474761 Mo Vodafone 30Ene. 18:56 0,1500 | |
| 669464644 MG Vodafone 15Feb. 20:14 0,1000 | |
| 664666664 Mo Euskaltel 2Feb. 10:34 0,1500 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment