You need to practice coding to think like a programmer in the same way you need to practice anything to be comfortable with it.
1) Write code
There are plenty of places online that will give you a bunch of problems to practice on and ponder upon. I like http://codekata.com/ but there are several others. You also have previous homework that you have the solution to. Having done it once, try to do it again from memory. If you need to peak, then peak. Repeat until you can code it from memory. Being comfortable with recalling how to do fundamental tasks will help you look at a problem and immediately start to see possible solutions; if you don't master the building blocks, what do you expect to build?
2) Read code
Read code online, read code in your text books, read code your peers write, read code strangers write... Just read you some code. This is especially helpful if the person decides to implement a particular solution in a different manner than the way you would have gone. Ask yourself, why did then go this route? Is it better, worse? Does it matter?
3) Know a language's best practices
Each programming language has its own way of doing things like array/list iteration, loops, condition checking etc. There's a lot of overlap, but a certain programming language can make a particular programing task very easy or very tedious. For example, list comprehensions in python can save you a lot of time, but not if you don't know about them.