输出字典的键(key)

  • Post author:
  • Post category:其他


几种方法如下:

a = {'季青林':2,'冯思越':"很帅","汪磊":"chun",5:520,3:"你是三八"}
b = list()
for i in a.keys():
    b.append(str(i))
print(",".join(b))

###############
print(",".join(sorted(list(str(key) for key in a.keys()))))   #这是对其进行排序后的输出方式,加了一个sorted

###############
l = []
for i in a:
   l.append(i)
print(l)
for m in l:
   print(m,end=',')

答案如下

季青林,冯思越,汪磊,5,3

3,5,冯思越,季青林,汪磊

[‘季青林’, ‘冯思越’, ‘汪磊’, 5, 3]

季青林,冯思越,汪磊,5,3,



版权声明:本文为Siyue_on_the_go原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。