Skip to content

Instantly share code, notes, and snippets.

@alv-alvarez
Created January 3, 2018 15:12
Show Gist options
  • Save alv-alvarez/b3dc180e2f455f36aad4e6c269285de5 to your computer and use it in GitHub Desktop.
Save alv-alvarez/b3dc180e2f455f36aad4e6c269285de5 to your computer and use it in GitHub Desktop.
Python Function Sort
#Ordenar fechas segun formato
from datetime import datetime
date = ['aug_17', 'jul_17', 'jun_17', 'may_17', 'oct_17', 'sep_17'] // Las fechas deben venir segun el formato del locate
date_sorted = sorted(date, key=lambda month: datetime.strptime(month, "%b_%y"))
#Ordenar segun arreglo dado
date = ['ago_17', 'jul_17', 'jun_17', 'may_17', 'oct_17', 'sep_17']
months = {"ene": 0, "feb": 1, "mar": 2, "abr": 3, "may": 4, "jun": 5, "jul": 6, "ago": 7, "sep": 8, "oct": 9, "nov": 10, "dic": 11}
def month_value(date):
return months[date.split('_')[0]]
date.sort(key=month_value)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment