Sto cercando di capire un esercizio di manipolazione di stringhe e di ordinamento. L'esercizio chiede di estrarre parole che hanno il tempo di riferimento (ad esempio, ore, giorni) dal testo, e ordinare le righe in base al tempo di estrarre in un ordine ascendente. Un esempio di dati:
Customer Text
1 12 hours ago — the customer applied for a discount
2 6 hours ago — the customer contacted the customer service
3 1 day ago — the customer reported an issue
4 1 day ago — no answer
4 2 days ago — Open issue
5
In questo compito sono in grado di identificare diverse difficoltà:
- time reference can be expressed as hours/days/weeks
- there are null values or no reference to time
- get a time format suitable and more general, e.g., based on the current datetime
Sul primo punto, ho notato che in genere le date di prima e, se presente, in modo che possa essere facile da estrarre. Sul secondo punto, se la dichiarazione potrebbe evitare i messaggi di errore a causa di dati incompleti o mancanti campi. Non so come risposta al terzo punto, però.
Il mio risultato atteso sarebbe:
Customer Text Sort by
1 12 hours ago — the customer applied for a discount 1
2 6 hours ago — the customer contacted the customer service 2
3 1 day ago — the customer reported an issue 2
4 1 day ago — no answer 2
4 2 days ago — Open issue 3
5