li = ["alex","wusir","eric","rain","alex"] #1 #print(len(li)) #2 #li.append("seven") #print(li) #3 #li.insert(0,"Tony") #print(li) #4 #li[1] = "Kelly" #print(li) #5 #l2 =[1,"a",3,4,"heart"] #li.extend(l2) #print(li) #6 #s = "qwer" #li.extend(s) #print(li) #7 #li.remove("eric") #print(li) #8 #l1 = li.pop(1) #print(l1) #print(li) #9 #del li[1:4] #print(li) #10 #li.reverse() #print(li) #11 #print(li.count("alex")) #二 ''' li = [1, 3, 2, "a", 4, "b", 5, "c"] l1 = li[0:3] print(l1) l2 = li[3:6] print(l2) l3 = li[:7:2] print(l3) l4 = li[1:6:2] print(l4) l5 = li[-1:] print(l5) l6 = li[5::-2] print(l6) ''' #三 lis = [2, 3, "k", ["qwe", 20, ["k1", ["tt", 3,"1"]], 89], "ab", "av"] #(1) #lis[3][2][1][0] = lis[3][2][1][0].upper() #lis[3][2][1][0] = "TT" #print(lis) #lis[1] = "100" #lis[3][2][1][1] = "100" #print(lis) #(2) #lis[3][2][1].remove(3) #lis[3][2][1].insert(1, "100") #print(lis) #(3) #lis[3][2][1][2] = 101 #print(lis) #lis[3][2][1][2] = int(lis[3][2][1][2].replace('1','101')) #print(lis) # 四 #li =["alex","eric","rain"] #l1 = "_".join(li) #print(l1) # 5,查找列表li中的元素,移除每个元素的空格, # 并找出以’A’或者’a’开头,并以’c’结尾的所有元素, # 并添加到一个新列表中,最后循环打印这个新列表。 # li = [‘taibai ’,’alexC’,’AbC ’,’egon’,’ Ritian’,’ Wusir’,’ aqc’] li = ['taibai ','alexC','AbC ','egon',' Ritian',' Wusir',' aqc'] b=[] # for i in li: # s=i.strip() # if (s.startswith("A")or s.startswith("a"))and s.endswith("c"): # b.append(s) # for x in b: # print(x) # for i in li: # s=i.strip() # if s[0].upper() == 'A' and s[-1] == 'c': # b.append(s) # for x in b: # print(x) # 6、开发敏感词语过滤程序,提示用户输入评论内容,如果用户输入的内容中包含特殊的字符: # 敏感词列表 li = ["苍老师","东京热",”武藤兰”,”波多野结衣”] # 则将用户输入的内容中的敏感词汇替换成***,并添加到一个列表中; # 如果用户输入的内容没有敏感词汇,则直接添加到上述的列表中。 li = ["苍老师", "东京热", "武藤兰", "波多野结衣"] new_li = [] info = input("请发言:") for i in li: if i == info: info = info.replace(i, "***") new_li.append(info) print(new_li)