以随机顺序打印字典的内容 [英] Printing contents of dictionary in random order
问题描述
我是Python的新手。事实上,今天是我在Python的第一天。我正在按照教程阅读有关字典的内容。
但我不知道字典内容的显示顺序是什么。
以下是我的代码:
dir = {''Z'':1, '' Y '':3 '' X '':5 '' V '':7,'U '':9 '' T '':2 '' S '':4 '' R '':6 '' Q '':8 '' P '':10};
print dir;
以下是输出:
{''Q'':8,''P'':10,''S'':4,''R'':6,''U'':9,''T'':2,' 'V'':7,''Y'':3,''X'':5,''Z'':1}
任何人都可以解释我是如何得到这个输出而不是原始序列中的列表。
PS:对于一个蹩脚的问题很抱歉:(
字典是无序集,因此内容可能以任何顺序出现。请参阅第5.5节此页 [ ^ 一>]。
I am fairly new to Python. Infact, today is my first day in Python. I was following a tutorial and read about dictionary.
But I don''t know what is the order in which contents of a dictionary are displayed.
Below is my code:
dir = {''Z'':1,''Y'':3,''X'':5,''V'':7,''U'':9,''T'':2,''S'':4,''R'':6,''Q'':8,''P'':10}; print dir;
and following is the Output:
{''Q'': 8, ''P'': 10, ''S'': 4, ''R'': 6, ''U'': 9, ''T'': 2, ''V'': 7, ''Y'': 3, ''X'': 5, ''Z'': 1}
Can anybody explain how I get this output and not the list in its original sequence.
P.S: Sorry for a lame question :(
Dictionaries are unordered sets, so the contents may appear in any sequence. See section 5.5 on this page[^].
这篇关于以随机顺序打印字典的内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!