Thinking of keys, always have them out before you get to your apartment. Standing in a vestibule or outside your building rooting in your bag for them screams "I'm not paying attention to what's going on!" If you drive, find your house key before you get out of your car. If you take public transportation, get them out before you get off at your stop, even if you have to walk a ways holding them.Always deadbolt your door behind you. If your apartment doesn't have one, insist one be installed or you install one yourself. Keep your windows locked. If you live on a floor with a fire escape right outside your window, NEVER sleep with that window open.Also, never rent an apartment on the ground floor. It's the easiest access for theives and rapists.
This should be obvious, but I had a friend get mugged a couple of weeks ago becaue he was walking home along (in Berkeley) at 2AM half drunk and carrying his nice digital camera in his hand. I suppose it's possible he would have been mugged anyway, but they didn't even bother to get his wallet. For God's sake, don't visibly carry expensive electronics around at night, especially when you're by yourself. I'd include iPods in this category. And if you're planning on having your laptop with you late at night you might want to carry it in a backpack or a bag that doesn't scream "laptop."