Yes. Other possibilities include eg He took comfort in/from the thought that he wasn't the only one who hadn't passed his finals. eg he took comfort in/from the thought that he wasn't the only one to fail his finals.
New words, one handy idiom, and a 2-minute quiz — delivered to your inbox to keep your streak alive.