相关疑难解决方法(0)

为什么字典中的顺序和设置是任意的?

我不明白如何通过'任意'顺序完成字典或python中的循环.

我的意思是,它是一种编程语言,所以语言中的所有内容都必须100%确定,对吗?Python必须有某种算法来决定选择字典或集合的哪一部分,第一,第二等等.

我错过了什么?

python dictionary set python-internals

145
推荐指数
5
解决办法
2万
查看次数

无序Python集的"顺序"

我知道Python中的集合是无序的,但我对它们显示的"顺序"感到好奇,因为它似乎是一致的.它们似乎每次都以相同的方式乱序:

>>> set_1 = set([5, 2, 7, 2, 1, 88])
>>> set_2 = set([5, 2, 7, 2, 1, 88])
>>> set_1
set([88, 1, 2, 5, 7])
>>> set_2
set([88, 1, 2, 5, 7])
Run Code Online (Sandbox Code Playgroud)

......和另一个例子:

>>> set_3 = set('abracadabra')
>>> set_4 = set('abracadabra')
>>> set_3
set(['a', 'r', 'b', 'c', 'd'])
>>>> set_4
set(['a', 'r', 'b', 'c', 'd'])
Run Code Online (Sandbox Code Playgroud)

我只是好奇为什么会这样.有帮助吗?

python python-internals

47
推荐指数
2
解决办法
9436
查看次数

为什么python会像这样订购我的字典?

这是我的字典

propertyList = {
    "id":           "int",
    "name":         "char(40)",

    "team":         "int",
    "realOwner":    "int",

    "x":            "int",
    "y":            "int",

    "description":  "char(255)",

    "port":         "bool",
    "secret":       "bool",
    "dead":         "bool",
    "nomadic":      "bool",

    "population":   "int",
    "slaves":       "int",
}
Run Code Online (Sandbox Code Playgroud)

但是当我用"\n".join(myDict)打印出来时,我得到了这个

name
nomadic
dead
port
realOwner
secret
slaves
team
y
x
population
id
description
Run Code Online (Sandbox Code Playgroud)

我知道字典是无序的,但每次出现都是一样的,我不知道为什么.

python dictionary

41
推荐指数
3
解决办法
4万
查看次数

标签 统计

python ×3

dictionary ×2

python-internals ×2

set ×1