我刚开始尝试使用Python(有VBA背景)。为什么这个字典会无序创建?它不应该是a:1,b:2...等等吗?
class Card:
def county(self):
c = 0
l = 0
groupL = {} # groupL for Loop
for n in range(0,13):
c += 1
l = chr(n+97)
groupL.setdefault(l,c)
return groupL
pick_card = Card()
group = pick_card.county()
print group
以下是输出结果:
{'a': 1, 'c': 3, 'b': 2, 'e': 5, 'd': 4, 'g': 7, 'f': 6, 'i': 9, 'h': 8, 'k': 11, 'j': 10, 'm': 13, 'l': 12}
或者,它只是无序地打印出来吗?
groupL[l] = c
可能是你想要的。 - abarnert