Dize manipülasyonu ve sıralama üzerine bir alıştırma yapmaya çalışıyorum. Alıştırma, metinden zaman referansı olan sözcükleri (örneğin, saatler, günler) çıkarmayı ve satırları artan bir sırada çıkarılan zamana göre sıralamayı ister. Bir veri örneği şöyledir:
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
Bu görevde birkaç zorluk tespit edebilirim:
- 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
İlk noktada, genellikle tarihlerin daha önce olduğunu, mevcut olup olmadığını, bu yüzden onları çıkarmanın kolay olabileceğini belirttim. İkinci noktada, bir ıf deyimi eksik / eksik alanlar nedeniyle hata iletilerinden kaçınabilir. Yine de üçüncü noktaya nasıl cevap vereceğimi bilmiyorum.
Beklenen sonucum şöyle olurdu:
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