i need help for this case :

m={}

m[1]=1

m[333]=333

m[2]=2

# Result:

{1: 1, 2: 2, 333: 333}

so even when i didn't enter '333' the last, i got this '333' listed in the end of the dictionary when print it out. why is this 'dictionary' doing auto sort? and how disable it? i can creata a function to re-sort to fix the order. but that's not what i want, i just simply want to print and get output order just like the order when i input the data. Is there any good explanation and is there any solution ?

解决方案

It is not sorting. dict is not ordered at all, so you cannot influence the key order in any way. There is collections.OrderedDict in 2.7 and 3.1+, there is also standalone module for 2.4-2.6.

python字典会自动排序,python:创建字典时如何禁用自动排序相关推荐

  1. python中字典的定义与如何创建字典

    字典(dict)的定义 有关字典的定义:- 字典是一个无序的数据类型,使用print输出时,通常与定义顺序不一致- 定义字典时,使用{}或dict().此时就揭示了为什么集合定义空集时不可直接使用大括 ...

  2. java 后台自动刷新请求_请求时token过期自动刷新token

    1.在开发过程中,我们都会接触到token,token的作用是什么呢?主要的作用就是为了安全,用户登陆时,服务器会随机生成一个有时效性的token,用户的每一次请求都需要携带上token,证明其请求的 ...

  3. python中的键不允许重复_为什么python允许您使用重复键创建字典

    >>> d = {'a' : 'b', 'a' : 'c'} >>> d {'a': 'c'} 不,这只是你使用预先存在的密钥初始化一个字典,它只是覆盖了现有密钥的 ...

  4. linux自动挂载ext4,创建ext4文件系统,并自动挂载

    实验环境如下: [root@Centos7 ~]# uname -r 3.10.0-693.el7.x86_64 [root@Centos7 ~]# cat /etc/redhat-release C ...

  5. python创建字典的两种方法要求键星期一到星期天_Python3笔记019 - 4.4 字典

    第4章 序列的应用 4.1 序列 4.2 列表 4.3 元组 4.4 字典 4.5 集合 4.6 列表.元组.字典.集合的区别 python的数据类型分为:空类型.布尔类型.数字类型.字节类型.字符串 ...

  6. python读取字典元素笔记_Python 学习笔记 - 字典

    Python 字典 字典是一种无序的.可修改的.可索引的容器. 字典使用花括号声明,具有键和值. mydic = { 'name':'孙悟空', 'origin':'猴子' } print(mydic ...

  7. python基础入门(9)之字典

    目录 Python字典 一.字典理解 1.1)创建字典与访问 1.2)字典长度 1.3)数据类型 二.访问字典 2.1)访问键名 2.2)访问健值 三.更改字典各种方法 四.添加字典项各种方法 五.删 ...

  8. python编程基础与应用-Python程序设计:从编程基础到专业应用

    基本信息 书名:Python程序设计:从编程基础到专业应用 :42.00元 作者:章宁,李海峰 编 出版社:机械工业出版社 出版日期:2019_03_01 ISBN:9787111620136 字数: ...

  9. python项目部署nginx_【python】Django web项目部署(Nginx+uwsgi)

    一.安装uwsgi 通过pip安装uwsgi. 测试uwsgi,创建test.py文件: 通过uwsgi运行该文件. 常用选项: http: 协议类型和端口号 processes : 开启的进程数量 ...

最新文章

  1. 计算机中音乐设备数字接口,一种计算机用声卡封存装置的制作方法
  2. axis2 java.net.url_axis,axis2调用.net的webservice
  3. why get_expanded_entityset is not called but works in Ke's laptop
  4. 对于多属性类型系统的数据库设计
  5. docker remote api未授权访问漏洞(端口:2375)
  6. Effective_STL 学习笔记(四) 用 empty 来代替检查 size() 是否为0
  7. mysql产生大量数据_mysql语句批量产生大量测试数据
  8. Atitit 卡片管理指南规范 attilax总结(内部身份卡,饭卡,交通卡 银行卡等)
  9. 网站死链查询-在线网站死链查询提交工具免费
  10. C语言求最大公约数的方法,辗转相除法,质因数分解法、短除法、更相减损法。
  11. Lumiprobe丨Lumizol RNA 提取试剂解决方案
  12. 【JavaWeb】JQuery实现广告显示和隐藏动画效果
  13. iOS关闭键盘的两种简单方法
  14. 什么是android应用程序未安装,Android 解决应用程序未安装的三种方法
  15. ubuntu 检测网络状态命令
  16. dedecms织梦后台登录一直提示验证码错误
  17. 实战Nagios NSCA方式监控Linux系统资源使用情况 -- Nagios配置篇 -- 被监控端
  18. UWP 和 WPF 对比
  19. ue/um-editor实现word图片复制
  20. java 简单万年历_java简单万年历

热门文章

  1. 日本6日游——大阪京都名古屋富士山横滨
  2. ps真实辉光插件:Oniric Glow Generator汉化版
  3. DNSPod十问王瑨:如何靠卖域名成为百亿美金上市公司?
  4. UnicodeEncodeError: 'latin-1' codec can't encode character '\u7537' in position 184: ordinal not in
  5. 利用.frm、.ibd恢复数据
  6. LeetCode 50_Pow(x, n) 乘方实现
  7. 各种开源许可 Lincense
  8. 2021/10/14程式培力刷題記錄
  9. 广度优先搜索(Breadth First Search)
  10. Linux按列合并两文件,列的拼合