>>> the_values = [u'abc', u'kfc', u'listproperty', u'models', u'new', u'newer', u'note', u'order', u'tag', u'test', u'type']
>>> the_keys = [1, 2, 1, 2, 1, 1, 1, 1, 2, 1, 1]
d2 = dict(zip(the_keys, the_values))
>>> d2
{1: u'type', 2: u'tag'}
"타입"과 "태그"만 사용하는 이유는 무엇입니까?키로 파이썬 사전 정렬하기
the_values
에 의해 the_keys
을 정렬하려고합니다.
>>> d2 = dict(zip(the_values, the_keys))
>>> d2
{u'abc': 1, u'models': 2, u'note': 1, u'tag': 2, u'kfc': 2, u'newer': 1, u'listproperty': 1, u'test': 1, u'new': 1, u'type': 1, u'order': 1}
감사 :
나는the_values
및
the_keys
작품의 순서를 전환하는 것으로 나타났습니다.
[표준] * 사전 *은 순서가 없으며 특정 키를 * 단일 값으로 매핑합니다. (키, 값) 쌍의 정렬 된 * 목록 *을 만들 수 있습니다. –