python: list
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 | #去重 A = [ 'geovindu' , '刘杰' , '江山' , '河水' , '刘杰' , 'geovindu' , '张三' , '李五' ] B = [] for i in A: if i not in B: B.append(i) print (B) C = set (A) print ( list (C)) # 移动位置 从index=3 要移的index 指定的位置index 1 index = 1 #新位置 oldindex = 3 #旧位置 show = [ '2A' , '3B' , '1C' , '4E' , '5A' ] temp = show[oldindex] for k in range (oldindex, index, - 1 ): #移到index 1 show[k] = show[k - 1 ] show[index] = temp print (show) print ( '*********' ) #移到index 0 index = 0 #新位置 oldindex = 3 #旧位置 show = [ '2A' , '3B' , '1C' , '4E' , '5A' ] temp = show[oldindex] for k in range (oldindex,index, - 1 ): show[k] = show[k - 1 ] show[index] = temp print (show) print ( '*********' ) # 移除 wait = [ 3001 , 4001 , 5001 , 2001 , 2002 , 3002 , 2003 , 4002 , 2004 , 2005 ] delindex = 2 #位置 for k in range (delindex, len (wait) - 1 ): wait[k] = wait[k + 1 ] wait[ len (wait) - 1 ] = 0 print (wait) print ( '*********' ) # 添加一个 添加位置 index 4 index = 4 #新位置 wait = [ 3001 , 4001 , 5001 , 2001 , 2002 , 3002 , 2003 , 4002 , 2004 , 2005 ] wait = wait + [ 0 ] for k in range ( len (wait) - 1 , index, - 1 ): wait[k] = wait[k - 1 ] wait[index] = 9001 print (wait) print ( '*********' ) # 添加一个 添加位置index 3 eca = [ "Tony" , "Paul" , "Kelly" , "Wendy" , "Jack" ] eca = eca + [''] index = 3 #新位置 nn = len (eca); for k in range (nn - 1 , index, - 1 ): eca[k] = eca[k - 1 ] eca[index] = "viky" print (eca) |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 | # encoding: utf-8 # 版权所有 2024 涂聚文有限公司 # 许可信息查看: # 描述: # Author : geovindu,Geovin Du 涂聚文. # IDE : vs code python 3.11 # Datetime : 2024/6/15 18:56 # User : geovindu # Product : Visual Studio Code # Project : pyBaiduAi # File : DuList.py # explain : 学习 import sys import os import io class DuList( object ): """ 操作列表 """ def __init__( self ) - > None : pass @staticmethod def MomveItem(oldindex: int ,newindex: int ,show: list ) - > list : """ 操作列表指定的某个元素的索引位置移到指定的新位置 :param oldindex: 旧位置索引值 :param newindex: 新位置索引值 :param show: 要移位位置的列表 :return:返回移位置的列表 """ #index=1 #新位置 #oldindex=3 #旧位置 #show = ['2A', '3B', '1C', '4E', '5A'] temp = show[oldindex] #获取指定索引值原元素 for k in range (oldindex, newindex, - 1 ): #移到index 1 show[k] = show[k - 1 ] show[newindex] = temp return show @staticmethod def DelItem(delindex: int ,show: list ) - > list : """ 操作删除列表指定的索引值的某个元素 :param oldindex: 位置索引值 :param show: 要移位位置的列表 :return:返回删除后的列表 """ # 移除 #show = [3001, 4001, 5001, 2001, 2002, 3002, 2003, 4002, 2004, 2005] #delindex = 2 #位置 for k in range (delindex, len (show) - 1 ): show[k] = show[k + 1 ] show[ len (show) - 1 ] = 0 show.pop( len (show) - 1 ) return show @staticmethod def AddItem(index: int ,value,show: list ) - > list : """ 列表添加指定索引位置的元素 :param index: 添加位置索引值 :param value: 添加值 :param show: 列表 :return:返回添加后的列表 """ # 添加一个 添加位置 index 4 # index=4 #新位置 #show = [3001, 4001, 5001, 2001, 2002, 3002, 2003, 4002, 2004, 2005] if ( type (value) = = int ): show = show + [ 0 ] elif ( type (value) = = str ): #show = show + [''] show = show + [ None ] else : show = show + [ None ] for k in range ( len (show) - 1 , index, - 1 ): show[k] = show[k - 1 ] show[index] = value return show |
调用:
1 2 3 4 5 6 7 8 9 10 11 12 13 | # Press the green button in the gutter to run the script. if __name__ = = '__main__' : #print_hi('PyCharm,python language') show = [ '2A' , '3B' , '1C' , '4E' , '5A' ] DuList.MomveItem( 3 , 1 ,show) print (show) wait = [ 3001 , 4001 , 5001 , 2001 , 2002 , 3002 , 2003 , 4002 , 2004 , 2005 ] DuList.DelItem( 2 ,wait) print (wait) wait = [ 3001 , 4001 , 5001 , 2001 , 2002 , 3002 , 2003 , 4002 , 2004 , 2005 ] newwait = DuList.AddItem( 2 , 8008 ,wait) print (newwait) |
vs 2022 要考虑文件编码,微软的IDE 一般是GB2312.所以还要人工设置一下。
哲学管理(学)人生, 文学艺术生活, 自动(计算机学)物理(学)工作, 生物(学)化学逆境, 历史(学)测绘(学)时间, 经济(学)数学金钱(理财), 心理(学)医学情绪, 诗词美容情感, 美学建筑(学)家园, 解构建构(分析)整合学习, 智商情商(IQ、EQ)运筹(学)生存.---Geovin Du(涂聚文)
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 无需6万激活码!GitHub神秘组织3小时极速复刻Manus,手把手教你使用OpenManus搭建本
· C#/.NET/.NET Core优秀项目和框架2025年2月简报
· Manus爆火,是硬核还是营销?
· 一文读懂知识蒸馏
· 终于写完轮子一部分:tcp代理 了,记录一下
2023-07-06 python: using pdfplumber Lib read pdf file
2020-07-06 csharp: Emgu.CV.OCR and Tesseract.OCR Optical Character Recognition
2018-07-06 MySQL chartset
2011-07-06 jQuery jToday Plugin