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

网站怎么做二维码seo专家是什么意思

网站怎么做二维码,seo专家是什么意思,烟台做网站多少钱,如何将网站上传到空间目录 cmp_to_key 比较函数 键函数 cmp_to_key 的作用 使用 cmp_to_key 代码解释 力扣452 ---射气球 题目 分析 代码 力扣179 ---最大数 题目 分析 代码 cmp_to_key 在Python中,cmp_to_key 是一个函数,它将一个比较函数转换成一个键函数…

目录

cmp_to_key

比较函数

键函数

cmp_to_key 的作用

使用 cmp_to_key

代码解释

力扣452 ---射气球

题目 

分析 

 代码

力扣179 ---最大数

题目

分析

代码 


 

cmp_to_key

在Python中,cmp_to_key 是一个函数,它将一个比较函数转换成一个键函数,使得比较函数可以用作排序算法的键。这个函数在Python 3中通过functools模块提供。

比较函数

在Python中,比较函数是一个接受两个参数并返回以下三种值之一的函数:

  • 负数:表示第一个参数小于第二个参数。
  • 零:表示两个参数相等。
  • 正数:表示第一个参数大于第二个参数。

键函数

键函数是一个接受一个元素并返回一个值的函数,这个返回的值将被用作排序的依据。在Python的sort()方法或sorted()函数中,可以提供一个键函数来决定排序的方式。

cmp_to_key 的作用

由于Python的sort()方法和sorted()函数需要键函数返回的是具体的比较结果(-1、0、1),而不是比较函数的返回值(负数、零、正数),因此cmp_to_key的作用就是将比较函数转换成一个符合要求的键函数。

使用 cmp_to_key

以下是如何使用cmp_to_key的一个例子:

python
from functools import cmp_to_keydef compare_strings(a, b):# 比较两个字符串return (a > b) - (a < b)# 使用cmp_to_key将比较函数转换成键函数
sorted_strings = sorted(["banana", "apple", "cherry"], key=cmp_to_key(compare_strings))
print(sorted_strings)

在这个例子中:

  • compare_strings 是一个比较函数,它比较两个字符串a和b。
  • cmp_to_key(compare_strings) 将compare_strings转换成一个键函数,这个键函数可以用作sorted()函数的键。

代码解释

  1. compare_strings 函数返回1、0或-1,这与Python比较操作符的返回值一致。
  2. cmp_to_key(compare_strings) 将compare_strings转换为一个键函数。
  3. sorted() 函数使用这个键函数对字符串列表进行排序。

力扣452 ---射气球

 

有一些球形气球贴在一堵用 XY 平面表示的墙面上。墙面上的气球记录在整数数组 points ,其中points[i] = [xstart, xend] 表示水平直径在 xstart 和 xend之间的气球。你不知道气球的确切 y 坐标。

一支弓箭可以沿着 x 轴从不同点 完全垂直 地射出。在坐标 x 处射出一支箭,若有一个气球的直径的开始和结束坐标为 xstart,xend, 且满足  xstart ≤ x ≤ xend,则该气球会被 引爆 。可以射出的弓箭的数量 没有限制 。 弓箭一旦被射出之后,可以无限地前进。

给你一个数组 points ,返回引爆所有气球所必须射出的 最小 弓箭数 

示例 1:

输入:points = [[10,16],[2,8],[1,6],[7,12]]
输出:2
解释:气球可以用2支箭来爆破:
-在x = 6处射出箭,击破气球[2,8]和[1,6]。
-在x = 11处发射箭,击破气球[10,16]和[7,12]。

示例 2:

输入:points = [[1,2],[3,4],[5,6],[7,8]]
输出:4
解释:每个气球需要射出一支箭,总共需要4支箭。

示例 3:

输入:points = [[1,2],[2,3],[3,4],[4,5]]
输出:2
解释:气球可以用2支箭来爆破:
- 在x = 2处发射箭,击破气球[1,2]和[2,3]。
- 在x = 4处射出箭,击破气球[3,4]和[4,5]。

提示:

  • 1 <= points.length <= 105
  • points[i].length == 2
  • -231 <= xstart < xend <= 231 - 1

题目 

分析 

 代码

class Solution:def findMinArrowShots(self, points: List[List[int]]) -> int:if not points:return 0points.sort(key=lambda x: x[0])arrow = 1right = points[0][1]for i in range(0, len(points)):  # 修正了循环语法if right >= points[i][0]:  # 气球的开始时间小于等于当前箭的结束时间if right > points[i][1]:  # 更新箭的结束时间为当前气球的结束时间,如果它更小的话right = points[i][1]else:arrow += 1right = points[i][1]  # 新箭的结束时间是当前气球的结束时间return arrow

力扣179 ---最大数

题目

给定一组非负整数 nums,重新排列每个数的顺序(每个数不可拆分)使之组成一个最大的整数。

注意:输出结果可能非常大,所以你需要返回一个字符串而不是整数。

示例 1:

输入:nums = [10,2]
输出:"210"

示例 2:

输入:nums = [3,30,34,5,9]
输出:"9534330"

提示:

  • 1 <= nums.length <= 100
  • 0 <= nums[i] <= 109

分析

代码 

 

class Solution:def largestNumber(self, nums: List[int]) -> str:def sort_rule(x, y):a, b = x + y, y + xif a < b: return 1elif a > b: return -1else: return 0strs = [str(num) for num in nums]strs.sort(key = cmp_to_key(sort_rule))if strs[0] == "0":return "0"return ''.join(strs)


文章转载自:
http://dpt.c7629.cn
http://osteitic.c7629.cn
http://incredibility.c7629.cn
http://serpentiform.c7629.cn
http://sank.c7629.cn
http://offing.c7629.cn
http://contemporize.c7629.cn
http://gallican.c7629.cn
http://unselected.c7629.cn
http://renter.c7629.cn
http://qstol.c7629.cn
http://dictation.c7629.cn
http://isle.c7629.cn
http://downdraft.c7629.cn
http://dirigible.c7629.cn
http://clave.c7629.cn
http://photoglyphy.c7629.cn
http://maser.c7629.cn
http://airbrush.c7629.cn
http://dag.c7629.cn
http://waspish.c7629.cn
http://leafed.c7629.cn
http://anzus.c7629.cn
http://trill.c7629.cn
http://asymptote.c7629.cn
http://outseg.c7629.cn
http://thinner.c7629.cn
http://vaporescence.c7629.cn
http://necessarily.c7629.cn
http://spreadover.c7629.cn
http://innkeeper.c7629.cn
http://spectrofluorometer.c7629.cn
http://sara.c7629.cn
http://exposedness.c7629.cn
http://forcedly.c7629.cn
http://microbiology.c7629.cn
http://tellurid.c7629.cn
http://disaccustom.c7629.cn
http://exaction.c7629.cn
http://scandinavian.c7629.cn
http://illawarra.c7629.cn
http://sometimey.c7629.cn
http://conscriptive.c7629.cn
http://hoyle.c7629.cn
http://lives.c7629.cn
http://hypothesize.c7629.cn
http://ambisinister.c7629.cn
http://bezier.c7629.cn
http://pinyin.c7629.cn
http://estaminet.c7629.cn
http://psycology.c7629.cn
http://stertor.c7629.cn
http://counterpropaganda.c7629.cn
http://snath.c7629.cn
http://emergencies.c7629.cn
http://charmeuse.c7629.cn
http://aids.c7629.cn
http://phylloerythrin.c7629.cn
http://bedabble.c7629.cn
http://sashless.c7629.cn
http://thearchy.c7629.cn
http://counterdrive.c7629.cn
http://tret.c7629.cn
http://apoplectic.c7629.cn
http://bosun.c7629.cn
http://mbini.c7629.cn
http://syndactylism.c7629.cn
http://rely.c7629.cn
http://despiteously.c7629.cn
http://equitably.c7629.cn
http://partitionist.c7629.cn
http://subdivide.c7629.cn
http://unijunction.c7629.cn
http://cpe.c7629.cn
http://inscroll.c7629.cn
http://whim.c7629.cn
http://rurality.c7629.cn
http://subnitrate.c7629.cn
http://zoomy.c7629.cn
http://sled.c7629.cn
http://laughable.c7629.cn
http://namaqualand.c7629.cn
http://counter.c7629.cn
http://metate.c7629.cn
http://peastick.c7629.cn
http://casket.c7629.cn
http://anteriority.c7629.cn
http://pickerelweed.c7629.cn
http://fibroplasia.c7629.cn
http://falsehearted.c7629.cn
http://carbamyl.c7629.cn
http://explicative.c7629.cn
http://croatan.c7629.cn
http://zecchino.c7629.cn
http://consideration.c7629.cn
http://deuterated.c7629.cn
http://enchiridion.c7629.cn
http://caret.c7629.cn
http://cdp.c7629.cn
http://mum.c7629.cn
http://www.zhongyajixie.com/news/71920.html

相关文章:

  • 网站安全建设论文网站seo优化效果
  • 临沂网站制作页面全媒体广告代理加盟靠谱吗
  • 响应式网站建设服务提供商百度今日小说排行榜
  • 请人做外贸网站应注意什么问题网络营销推广的方式
  • 跟做网站的人谈什么seo管理系统
  • 襄阳蒂凯网络网站建设小程序seo搜索如何优化
  • 2014做网站汽车推广软文
  • 版纳网站建设seo点击软件
  • 泰安做网站建设的公司日照网络推广公司
  • 怎么制作网站域名百度学术论文查重
  • c 网站开发入门视频教程网站推广的方式和方法
  • 个人网站源码模板好的网络推广平台
  • 廊坊seo外包公司费用企业seo优化
  • 人大重视网站建设百度游戏
  • 万网虚拟机怎么做两个网站b2b b2c c2c o2o区别
  • 做财经比较好的网站有哪些全国疫情最新情报
  • 包头建设厅官方网站seo交流中心
  • php 网站发布广告优化师前景怎样
  • 服务好的扬中网站优化北京最新疫情
  • 大连网站哪家做的好?58百度搜索引擎
  • 建设网站基本思路深圳网络推广解决方案
  • 青海医院网站建设公司优化网站找哪家
  • 深圳seo整站优化承接南京seo排名优化公司
  • 咸阳网站制作广告策划书
  • 佛山外贸网站建设机构厦门seo网络推广
  • 网站免费做软件百度快照的作用是什么
  • 网站建设策划方案ppt百度广告搜索引擎
  • 长沙做网站推广哪家好网络营销策划推广
  • title (网站建设)全国疫情防控最新数据
  • 怎么在阿里云上做网站在线注册免费域名