0

I'm having a bit of trouble wrapping my head around this problem. I'm still a novice at coding but any help would be appreciated.

Given this list:

[['https://www.tesla.com/careers/search/job/quality-inspection-engineer-general-assembly-81255', 'Engineering & Information Technology', 'Fremont, California', '01/11/2021'], ['https://www.tesla.com/careers/search/job/software-factory-firmware-integration-engineering-internship-fall-2021-80356', 'Engineering & Information Technology', 'Fremont, California', '12/29/2020'], ['https://www.tesla.com/careers/search/job/product-support-engineer-infotainment-78566', 'Engineering & Information Technology', 'Palo Alto, California', '12/03/2020'], ['https://www.tesla.com/careers/search/job/data-engineer-energy-operations-asset-management-79956', 'Engineering & Information Technology', 'Fremont, California', '12/21/2020'], ['https://www.tesla.com/careers/search/job/staff-software-engineer-battery-engineering-80562', 'Engineering & Information Technology', 'Fremont, California', '01/03/2021'], ['https://www.tesla.com/careers/search/job/antenna-ota-test-technician-79281', 'Engineering & Information Technology', 'Fremont, California', '12/14/2020']]

How would I go about sorting this list using the date given in each sub-list?

mhawke
  • 84,695
  • 9
  • 117
  • 138

1 Answers1

0

Check this out: How do I sort this list in Python, if my date is in a String?

Your solution is similar, but with a list instead of a dict:

.sort(key=lambda x: datetime.datetime.strptime(x[3], '%Y-%m-%d'))

More detail: sort is powerful because you pass a function to it that will take each element you are sorting and sort by the calculation it returns. In this case, we are calculating the date object (using the datetime library) of the 4th element in the list.

effprime
  • 578
  • 3
  • 10