Hello and welcome TomSjogren, Basically you need to sort the list of sets like this:
media = entry['media']
sorted_media = sorted(media, key=lambda m:m['rank'])
I am not familiar with django, but I think it would be like this then:
%for m in sorted_media:
<td valign="top">
<img width='200' src='{{m['media_link']}}'><br>
Media Caption: {{m['caption']}}<br>
Rank: {{m['rank']}}</td>
%end