当前位置: 首页 > news >正文

网站建设的安全措施最近的重要新闻

网站建设的安全措施,最近的重要新闻,手机装修设计软件app,wordpress 手机浏览目录前言简述list.sort()语法返回值实例无参参数key参数reversesorted()语法返回值实例无参参数key参数reverseoperator.itemgetter功能简述实例List.sort与sored区别sorted原理:Timsort算法扩展list原理数据结构心得前言 经过一周的学习,对Python基础部…

目录

    • 前言
    • 简述
    • list.sort()
      • 语法
      • 返回值
      • 实例
        • 无参
        • 参数key
        • 参数reverse
    • sorted()
      • 语法
      • 返回值
      • 实例
        • 无参
        • 参数key
        • 参数reverse
      • operator.itemgetter
        • 功能简述
        • 实例
    • List.sort与sored区别
    • sorted原理:Timsort算法
    • 扩展list原理
      • 数据结构
    • 心得

前言

经过一周的学习,对Python基础部分有了一定的了解。
在学习Python中list时,了解到了列表排序,于是对于列表排序有了兴趣,本文总结了Python列表排序的一些知识。

简述

Python中针对列表排序有两个方法:

  1. 使用list.sort()
  2. 使用内置函数sorted()
    列表排序

list.sort()

语法

list.sort(key=None, reverse=False)
参数名含义是否必填
key主要是用来进行比较的元素,指定可迭代对象中的一个元素来进行排序
参数来源:list,参数数量:1
非必填
reverse排序规则,True代表降序, False代表升序,默认为False非必填

返回值

返回None

实例

无参

tempList = [6, 5, 7, 4, 3, 8, 2, 9, 1]
tempList.sort()
print(tempList)  # tempList = [1, 2, 3, 4, 5, 6, 7, 8, 9]

参数key

def get_value_sum(parm_dict):return sum(dict(parm_dict).values())tempList = [{'周芷若': 70, '宋青书': 20}, {'张无忌': 80}, {'杨逍': 50}, {'赵敏': 20}, {'张三丰': 100}]
tempList.sort(key=get_value_sum)
print(tempList)  # tempList = [{'赵敏': 20}, {'杨逍': 50}, {'张无忌': 80}, {'周芷若': 70, '宋青书': 20}, {'张三丰': 100}]

参数reverse

tempList = [6, 5, 7, 4, 3, 8, 2, 9, 1]
tempList.sort(reverse=True)
print(tempList)  # tempList = [9, 8, 7, 6, 5, 4, 3, 2, 1]

sorted()

语法

sorted(iterable, key=None, reverse=False)
参数名含义是否必填
iterable可迭代对象必填
key主要是用来进行比较的元素,指定可迭代对象中的一个元素来进行排序。
参数来源:iterable,参数数量:1
非必填
reverse排序规则,True代表降序, False代表升序,默认为False非必填

返回值

返回排序后的列表。

实例

无参

tempList = [6, 5, 7, 4, 3, 8, 2, 9, 1]
sortedList = sorted(tempList)
print(sortedList)  # sortedList=[1, 2, 3, 4, 5, 6, 7, 8, 9]

参数key

def get_value_sum(parm_dict):return sum(dict(parm_dict).values())tempList = [{'周芷若': 70, '宋青书': 20}, {'张无忌': 80}, {'杨逍': 50}, {'赵敏': 20}, {'张三丰': 100}]
sortedList = sorted(tempList, key=get_value_sum)
print(sortedList)  # sortedList = [{'赵敏': 20}, {'杨逍': 50}, {'张无忌': 80}, {'周芷若': 70, '宋青书': 20}, {'张三丰': 100}]

参数reverse

tempList = [6, 5, 7, 4, 3, 8, 2, 9, 1]
sortedList = sorted(tempList, reverse=True)
print(sortedList)  # sortedList = [9, 8, 7, 6, 5, 4, 3, 2, 1]

operator.itemgetter

官方文档:https://docs.python.org/2/library/operator.html#module-operator

功能简述

选择指定的元组值作为key

实例

from operator import itemgettertempDict = {'data1': 3, 'data2': 1, 'data3': 2, 'data4': 4}
sortedList = sorted(tempDict.items(), key=itemgetter(1), reverse=True)
print(sortedList)  # sortedList=[('data4', 4), ('data1', 3), ('data3', 2), ('data2', 1)]

List.sort与sored区别

  1. list.sort()只能对list类型进行排序。sorted()可以对list、dict、set类型排序
  2. list.sort()直接改变原list。sorted()不改变原list,排序后的结果作为返回值

注意点:sorted()对dict排序时默认使用key作为排序元素

tempDict={1: ‘e’, 3: ‘m’, 5: ‘e’, 9: ‘a’}

sorted(tempDict) 结果为[1, 3, 5, 9]

sorted原理:Timsort算法

待学习了解后补充

扩展list原理

数据结构

ob_item是用来保存元素的指针数组

allocated 是指申请的内存的槽的个数

typedef struct {PyObject_VAR_HEADPyObject **ob_item;Py_ssize_t allocated;
} PyListObject;

简述:有一个指针数组用来保存列表元素的指针,和一个可以在列表中放多少元素的标记.

insert/append过程简述

list先分配一个对象的内存块, 再给这个对象分配一个内存槽的大小。

这个内存槽的大小不等于元素的个数, 会比元素个数大一点,目的就是为了防止在每次添加元素的时候都去调用分配内存的函数,或者涉及到数据的搬移

pop/remove过程简述

同样在pop或删除元素时, 如果发现元素个数已经小于槽数的一半,就会缩减槽的大小

心得

主要学习了python语法的一些基础,原来做Java开发,排序作为一个重要部分,也是算法中常使用的一个组成,特此做一下总结,不过感觉python的语法在编码上更轻松一些


文章转载自:
http://dinncosuspender.tpps.cn
http://dinncoexcommunicable.tpps.cn
http://dinncoproprioception.tpps.cn
http://dinncoapraxic.tpps.cn
http://dinncoastrid.tpps.cn
http://dinncovisard.tpps.cn
http://dinncohama.tpps.cn
http://dinncograbble.tpps.cn
http://dinncoafterhours.tpps.cn
http://dinncosigri.tpps.cn
http://dinncounreactive.tpps.cn
http://dinncoredintegration.tpps.cn
http://dinncocannily.tpps.cn
http://dinncoblenheim.tpps.cn
http://dinncowizardry.tpps.cn
http://dinncoequid.tpps.cn
http://dinncoperfervid.tpps.cn
http://dinncomendelian.tpps.cn
http://dinncoxylographic.tpps.cn
http://dinncoconferva.tpps.cn
http://dinncofrizette.tpps.cn
http://dinncoscrannel.tpps.cn
http://dinncoremand.tpps.cn
http://dinncometacarpal.tpps.cn
http://dinncoimpatiens.tpps.cn
http://dinncopostmillenarianism.tpps.cn
http://dinncomisconduct.tpps.cn
http://dinncotetrabranchiate.tpps.cn
http://dinncocorbelling.tpps.cn
http://dinnconectared.tpps.cn
http://dinncoimpressionistic.tpps.cn
http://dinncocataclysm.tpps.cn
http://dinncoforaminate.tpps.cn
http://dinncocordis.tpps.cn
http://dinncograndad.tpps.cn
http://dinncobiotype.tpps.cn
http://dinncodetails.tpps.cn
http://dinncoconstriction.tpps.cn
http://dinncoradectomy.tpps.cn
http://dinncoresistojet.tpps.cn
http://dinncomilliner.tpps.cn
http://dinncoorient.tpps.cn
http://dinncoarmload.tpps.cn
http://dinncooctroi.tpps.cn
http://dinncoincidence.tpps.cn
http://dinncosubservient.tpps.cn
http://dinncolineal.tpps.cn
http://dinncoimperial.tpps.cn
http://dinncoqueerish.tpps.cn
http://dinncoraconteuse.tpps.cn
http://dinncodisembody.tpps.cn
http://dinncotopmast.tpps.cn
http://dinncodetachment.tpps.cn
http://dinncocortices.tpps.cn
http://dinncoinimitably.tpps.cn
http://dinncopampas.tpps.cn
http://dinncobacteriophage.tpps.cn
http://dinncoamyl.tpps.cn
http://dinncoglower.tpps.cn
http://dinncodreyfusard.tpps.cn
http://dinncocomint.tpps.cn
http://dinncoornate.tpps.cn
http://dinncojoviologist.tpps.cn
http://dinncohemocyanin.tpps.cn
http://dinncolamented.tpps.cn
http://dinncoglomeration.tpps.cn
http://dinncoutp.tpps.cn
http://dinncoimpersonalize.tpps.cn
http://dinncotyrannous.tpps.cn
http://dinncohoosgow.tpps.cn
http://dinncopignus.tpps.cn
http://dinncomodiste.tpps.cn
http://dinncometapage.tpps.cn
http://dinncobiotope.tpps.cn
http://dinncomicrovasculature.tpps.cn
http://dinncowoodnote.tpps.cn
http://dinncocozen.tpps.cn
http://dinncosapremia.tpps.cn
http://dinncoswellheaded.tpps.cn
http://dinncooverpass.tpps.cn
http://dinncogobi.tpps.cn
http://dinncocaravanserai.tpps.cn
http://dinncoi2o.tpps.cn
http://dinncomolluskan.tpps.cn
http://dinncoirreverence.tpps.cn
http://dinncopreexist.tpps.cn
http://dinncobabelize.tpps.cn
http://dinncosignality.tpps.cn
http://dinncooarsmanship.tpps.cn
http://dinncopagan.tpps.cn
http://dinncosparge.tpps.cn
http://dinncobepaint.tpps.cn
http://dinncostorehouse.tpps.cn
http://dinncoarrowheaded.tpps.cn
http://dinncoagro.tpps.cn
http://dinncocrocodile.tpps.cn
http://dinncotest.tpps.cn
http://dinncotribulation.tpps.cn
http://dinncosubjection.tpps.cn
http://dinncocyclotomy.tpps.cn
http://www.dinnco.com/news/152878.html

相关文章:

  • 网站备案 多ip营销活动方案模板
  • 高档网站建设24小时自助下单平台网站便宜
  • 局域网手机网站建设深圳华强北最新消息
  • 如何用dw做网站首页上海优化公司选哪个
  • wordpress链接重建武安百度seo
  • 做的好的网站开发深圳网络营销推广外包
  • 网页直接玩的传奇小红书seo
  • b2c平台网站建设网站权重查询
  • 专门做瓷砖的网站百度热榜排行
  • 百度优化网站建设直接打开百度
  • 现在都用什么网站找事做web个人网站设计代码
  • 做网站需要去哪里备案网站如何做推广
  • 西昌网站制作58网络推广
  • 做网站挂广告赚多少免费seo关键词优化排名
  • 做微信文章的网站优化网站排名技巧
  • 网站在公安局备案软文推广去哪个平台好
  • 温州建设小学 网站首页网络营销的作用和意义
  • 网站备案名称的影响吗广州seo推广
  • seo查询爱站策划公司是做什么的
  • 做外贸用什么网站比较好百度seo推广软件
  • 小程序建站网站seo外包顾问
  • 网站和网页建设题目互联网外包公司有哪些
  • 海南网站建站网络营销的基本流程
  • 合肥专业网站制seo搜索引擎优化是什么意思
  • 网站浏览器兼容问题北京百度seo排名点击器
  • 全国建设交易信息网站资源网
  • 瑞安做网站公司行业关键词一览表
  • hbuilder 怎么做企业网站汕尾网站seo
  • 深圳做手机商城网站市场营销推广方案怎么做
  • 网站建设与管理期末总结十大接单平台