【问题标题】:Dictionaries in specific format特定格式的字典
【发布时间】:2021-04-03 14:17:44
【问题描述】:

我需要以下代码的一种特定格式

ROOM_CATEGORIES={
    ('Elt','Elite'),
    ('Lux','Luxury'),
    ('Sig','Signature')
    }

上面的代码我想要{'Sig':'Signature','Lux':'Luxury','Elt':'Elite'}

【问题讨论】:

    标签: python django django-views


    【解决方案1】:

    需要先排序,然后调用dict转换排序后的元组:

    dict(
        sorted(ROOM_CATEGORIES, reverse=True)
    )
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-10-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多