Say I make a program that keeps track of the days I worked and the hours I worked, would I use a dictionary? And how would I differentiate from a Monday on week 1 from a Monday on week 2? How do I get it to store this information after I close the program? (Python Language)
I would probably create a timesheet object for each week, or pay period. Each timesheet object might have a collection of days, with hours worked or times clocked in and out.
For persistent storage for a web site, I'd use a database like mysql. For an application running on a single machine I'd maybe use pickle, or a flat file system maybe.
A dictionary is a good way to store the data while your program is running.
There are a number of ways to add some data permanence (so it's around after you close the program). The Python modules pickle and shelve are useful and easy to use. One issue with these is that you can't easily inspect the data outside of a Python program. There are also modules to read and write text files in the JSON and XML formats, and JSON is particularly easy to read in a text editor. If you aren't already proficient, the databases like MySQL are way more than you need for a personal program like you mention and unless you want to invest some time into learning how to use them, you should go with a simpler solution.
As for the Monday on week 1 vs week 2, you have many options. You could use the actual date (this seems like a good idea to me), or you could key the dictionary with tuples, like ("Monday", 1). The main rule is that dictionary keys must be immutable (ints, strings, tuples -- that contain only immutable objects, etc), but not (dictionaries, lists, etc).
I took the opposite approach when designing this application for my own use.
In my experience, the biggest problem with timekeeping applications is data entry. So I decided to make my app use the simplest and most flexible data entry tool available: a text editor. I keep notes in a text file and intermingle timekeeping entries in them, so an excerpt looks like this:
Monday 5/10/09
release script ok this week
open a case on the whole code-table-foreign-key thing
- CUS1 2.0 Generate and release version 1.0.45.
need to get dma to spec out the RESPRB configuration, see case 810
MH section complete - one to go!
- CUS2 4.0 Configure and test Mental Health section.
Tuesday 5/11/09
... and so on
I'm consistent in starting each day with the proper heading, and the format of actual timekeeping entries, as you can see, is pretty simple. A simple scanner and state machine is all it takes to extract the data - basically, I just look for lines that begin with a weekday or a hyphen, and ignore everything else.
So that the program doesn't get too slow when parsing the notes files, I create a new notes file every year. (Even at the end of December the parsing process doesn't take more than 1/16 of a second.)
I wouldn't do it this way if I had to process hundreds of peoples' timekeeping entries, because the user does have to have a bit of a clue, and the parsing time would begin to add up after a while. On the other hand, keeping this data in a human-readable text file that I can store other stuff in (and keep under version control, and diff, and so on) is just incredibly useful.