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

厦门做模板网站的公司珠海做网站找哪家公司

厦门做模板网站的公司,珠海做网站找哪家公司,成都网站优化哪家好,网站安全等级评审在哪里做我们可以给列表中的所有数字分配一个唯一的值#xff0c;重复时它会保留给它的值。这是一个非常常见的问题#xff0c;在Web开发中#xff0c;处理物品id时会遇到。让我们讨论一下解决这个问题的一些方法。 1. 使用enumerate() 列表解析 # initializing list test_list …我们可以给列表中的所有数字分配一个唯一的值重复时它会保留给它的值。这是一个非常常见的问题在Web开发中处理物品id时会遇到。让我们讨论一下解决这个问题的一些方法。 1. 使用enumerate() 列表解析 # initializing list test_list [1, 4, 6, 1, 4, 5, 6]# printing the original list print(The original list is : str(test_list))# using list comprehension enumerate # assign unique value to list elements temp {i: j for j, i in enumerate(set(test_list))} res [temp[i] for i in test_list]# printing result print(The unique value list is : str(res)) 输出 The original list is : [1, 4, 6, 1, 4, 5, 6] The unique value list is : [0, 1, 3, 0, 1, 2, 3]2. 使用setdefault() map() count() from itertools import count# initializing list test_list [1, 4, 6, 1, 4, 5, 6]# printing the original list print(The original list is : str(test_list))# using setdefault() map() count() # assign unique value to list elements res list(map({}.setdefault, test_list, count()))# printing result print(The unique value list is : str(res)) 输出 The original list is : [1, 4, 6, 1, 4, 5, 6] The unique value list is : [0, 1, 2, 0, 1, 5, 2]3. 使用innot in操作符和index # initializing list test_list [1, 4, 6, 1, 4, 5, 6]# printing the original list print (The original list is : str(test_list))# assign unique value to list elements x[] for i in test_list:if i not in x:x.append(i) res[] for i in test_list:res.append(x.index(i))# printing result print (The unique value list is : str(res)) 输出 The original list is : [1, 4, 6, 1, 4, 5, 6] The unique value list is : [0, 1, 2, 0, 1, 3, 2]4. 使用reduce() from functools import reducetest_list [1, 4, 6, 1, 4, 5, 6] # printing the original list print (The original list is : str(test_list))unique_list reduce(lambda l, x: l [x] if x not in l else l, test_list, [])res [unique_list.index(i) for i in test_list] # printing result print (The unique value list is : str(res)) 输出 The original list is : [1, 4, 6, 1, 4, 5, 6] The unique value list is : [0, 1, 2, 0, 1, 3, 2]5. 使用sorted()和bisect_left() import bisect# initializing list test_list [1, 4, 6, 1, 4, 5, 6]# printing the original list print (The original list is : str(test_list))# assign unique value to list elements using sorted() and bisect_left() sorted_list sorted(test_list) res [] for i in test_list:idx bisect.bisect_left(sorted_list, i)res.append(idx)# printing result print (The unique value list is : str(res)) 输出 The original list is : [1, 4, 6, 1, 4, 5, 6] The unique value list is : [0, 2, 5, 0, 2, 4, 5]6. 使用numpy import numpy as nptest_list [1, 4, 6, 1, 4, 5, 6] # printing the original list print(The original list is:, test_list)# convert list to numpy array arr np.array(test_list)# get unique values and their indices unique_arr, unique_indices np.unique(arr, return_inverseTrue)# get indices of unique values for each element in original list res unique_indices.tolist()# printing result print(The unique value list is:, res)输出 The original list is: [1, 4, 6, 1, 4, 5, 6] The unique value list is: [0, 1, 3, 0, 1, 2, 3]
http://www.w-s-a.com/news/66964/

相关文章:

  • 室内设计素材网站推荐郑州专业做淘宝网站建设
  • 新建的网站怎么做seo优化模板规格尺寸及价格
  • 平湖网站设计做电子元器件销售什么网站好
  • 可视化网站模板我想建个网站网站怎么建域名
  • 达州网站建设qinsanw南京市建设发展集团有限公司网站
  • django 网站开发实例公司排行榜
  • 韩国做美食网站阳江网站建设 公司价格
  • 网站开发哪里接业务长春高端模板建站
  • 深圳网站制作公司方案dw一个完整网页的代码
  • asp手机网站源码下载做seo推广网站
  • 网站优化建议怎么写网站维护主要有哪些内容和方法
  • 建设网站需要钱吗网络推广加盟
  • 高清素材图片的网站泰安网签备案查询
  • 自助网站建设怎么建设房地产的最新政策
  • 企业网站 生成html网站侵权怎么做公证或证据保存
  • php 手机网站cms系统购物网站制作流程
  • 网络公司网站开发河北省城乡住房和建设厅网站
  • 做网站配置wordpress 中文api
  • 怎样把网站做的好看县蒙文网站建设汇报
  • 网站的优化什么做广西桂林新闻最新消息
  • 做网站准备什么软件搜索引擎广告推广
  • 网站开发地图板块浮动网页设计与制作的模板
  • 中国建设招聘信息网站昆明做网站建设的公司排名
  • 那些网站可以做自媒体wordpress 分类seo
  • 淮安市盱眙县建设局网站北京西站到八达岭长城最快路线
  • 在线免费网站企业查查官网入口官网
  • 天津网站优化公司哪家专业超融合系统
  • 邹平网站建设公司报价网站建设备案多长时间
  • 三合一网站开发教程wordpress主题汉化中文版
  • 广州网站建设高端全网营销图片