Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Honest question. What is wrong with something like that? I could see it justified by saving the overhead of a complex Date class.


It's just inelegant. A better approach would be an array where you return the content at the index.


If you are going this route why not use a switch?

Or just an array.


python have no switch


I had the same question. I had these thoughts:

It looks like python, so the semi-colons are unnecessary.

If you want to rid yourself of datetime for whatever reason, implement it as a list, returning name_of_day[x], so that you can start the week on a Sunday(=0) easily if you want to.

Beyond that, I'm stuck too :-(


Two words: mapping structures.


Python ships with a standard datetime class which is powerful enough to represent time, and there is a ubiquitous module, dateutil, which extends it to do nearly anything people need to do with dates regularly.

Additionally, one would normally use an array of names and index it:

  days = ["Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"]
  that_day_you_wanted = days[x]




Consider applying for YC's Fall 2026 batch! Applications are open till July 27.

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: