python问题

python读取文件时提示"UnicodeDecodeError: ‘gbk’ codec can’t decode byte 0x80 in position 205: illegal multibyte sequence"

解决办法1.
FILE_OBJECT= open('order.log','r', encoding='UTF-8')
解决办法2.
FILE_OBJECT= open('order.log','rb')

map排序:

1.按key排序:
items=dict.items()
items.sort()
 
sorted(dict.items(),key=lambda x:x[0],reverse=False)
 
2.按value排序
sorted(dict.items(),key=lambda x:x[1],reverse=False)
 
(ps:在python2.x中还是有cmp函数的,3.x中已经没有了,但是引入了
import operator       #首先要导入运算符模块
operator.gt(1,2)      #意思是greater than(大于)
operator.ge(1,2)      #意思是greater and equal(大于等于)
operator.eq(1,2)      #意思是equal(等于)
operator.le(1,2)      #意思是less and equal(小于等于)
operator.lt(1,2)      #意思是less than(小于)
)
map取最大最小值:
方法一:
max(dict,key=dict.get)
min(dict,key=dict.get)
方法二:
min(d.items(), key=lambda x: x[1])
min(d.items(), key=lambda x: x[1][0]
min(d.items(), key=lambda x: x[1])[1]
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值