我有一个由(名称,值)对组成的python字典,像这样
pyDictionary = {"Bob":12,"Mellissa":12,"roger":13}
Run Code Online (Sandbox Code Playgroud)
我想做的就是获得上述字典的排序版本,在该排序中,首先对值赋予第一个属性,然后进行排序,如果两对值相同,则应通过字典比较这些名称来进行比较。
我如何在python3.7中实现呢?
请考虑以下代码片段。
<!--templates/home.html-->
{% extends 'base.html' %}
{% load static %}
{% block content %}
{% for post in object_list %}
<div class = 'post-entry'>
<h2><a href="{% url 'post_detail' post.pk %}">{{ post.title }}</h2>
<p>{{ post.body }}</p>
</div>
{% endfor %}
<script type = "text/javascript" src = "{% static 'js/test.js' %}"></script>
{% endblock content %}
Run Code Online (Sandbox Code Playgroud)
和
<!--templates/home.html-->
{% extends 'base.html' %}
{% load static %}
{% block content %}
{% for post in object_list %}
<div class = 'post-entry'>
<h2><a href="{% url …Run Code Online (Sandbox Code Playgroud)