Ver Mensaje Individual
  #2 (permalink)  
Antiguo 02/12/2012, 16:41
Avatar de razpeitia
razpeitia
Moderador
 
Fecha de Ingreso: marzo-2005
Ubicación: Monterrey, México
Mensajes: 7.321
Antigüedad: 19 años, 1 mes
Puntos: 1360
Respuesta: Problema para ordenar listas en python

Supon que mi_archivo.txt tiene lo siguiente:
Código:
Periodo|Ajuste Cierre
1|388.39 
2|385.39 
3|376.84
7|392.46
23|416.11
Código Python:
Ver original
  1. import csv
  2.  
  3. my_list = []
  4. with open('mi_archivo.txt', 'rb') as csvfile:
  5.     reader = csv.reader(csvfile, delimiter='|')
  6.     reader.next() # Ignore headers
  7.     for row in reader:
  8.         my_list.append((int(row[0]), float(row[1])))
  9.  
  10. my_list.sort()
  11. for x, y in my_list:
  12.     print x, y