Skip to content

Instantly share code, notes, and snippets.

@juanpabloaj
Created June 12, 2012 22:40
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save juanpabloaj/2920582 to your computer and use it in GitHub Desktop.
Save juanpabloaj/2920582 to your computer and use it in GitHub Desktop.
ejemplo python: suma columna
dato1 1 10
dato2 2 20
dato3 3 30
# dasadads
dato4 4 40
dato5 5 50
# dads
dato6 6 60
dato7 7 70
dato8 8 80
dato9 9 90
dato10 10 100
#!/usr/bin/python
# -*- coding: utf-8 -*-
for i in range(5):
nombre = 'salida0' + str(i) + '.txt'
archivo = open(nombre,'a')
archivo.write(str(i)+'\n')
archivo.close()
#!/usr/bin/python
# -*- coding: utf-8 -*-
def media(lista):
largo = len(lista)
suma = sum(lista)
return suma/largo
archivo = open('datos.txt')
valores = []
for l in archivo:
if '#' not in l:
l = l.replace('\n','')
leidos = l.split('\t')
print leidos
valores.append(int(leidos[2]))
print media(valores)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment