Many of David's psalms follow the pattern found in these two verses—a transition from prayer to praise. David was not afraid to come to God and express his true feelings and needs. Thus, his spirit was lifted, and he praised God, his helper, protector, and friend.
Psalms 54:5
David asked God to repay evil to his enemies. He simply stated his confidence in God's promise. Pro 26:27 warns that those who cause trouble will reap trouble. What we have intended for others may blow up in our own face. To be honest and straightforward before God and others is simpler, easier, and safer in the long run.