1 # encoding:utf-8 2 3 # 查找列表中元素,移除每个元素的空格,并查找以a或A开头并且以c结尾的元素。 4 5 li = ["alec", " aric", "Alex", "Tony", "rain"] 6 tu = ("alec", " aric", "Alex", "Tony", "rain") 7 dic = {'k1': "alex", ' k2': ' aric', "k3": "Alex", "k4": "Tony"} 8 9 li_new = [] 10 li_aAc = [] 11 tu_new = [] 12 tu_aAc = [] 13 dic_new = {} 14 dic_aAc = {} 15 16 for i in li: 17 k = i.strip() 18 li_new.append(k) 19 if k.startswith("a") or k.startswith("A"): 20 if k.endswith("c"): 21 li_aAc.append(k) 22 else: 23 continue 24 print("---------------------------") 25 print("原始数据{}".format(li)) 26 print(li_new) 27 print(li_aAc) 28 29 for i in tu: 30 k = i.strip() 31 tu_new.append(k) 32 if k.startswith("a") or k.startswith("A"): 33 if k.endswith("c"): 34 tu_aAc.append(k) 35 else: 36 continue 37 print("---------------------------") 38 print("原始数据{}".format(tu)) 39 print(tuple(tu_new)) 40 print(tuple(tu_aAc)) 41 42 for index_i, i in dic.items(): 43 k = index_i.strip() 44 j = i.strip() 45 dic_new[k] = j 46 if j.startswith("a") or j.startswith("A"): 47 if j.endswith("c"): 48 dic_aAc[k] = j 49 print("---------------------------") 50 print("原始数据{}".format(dic)) 51 print(dic_new) 52 print(dic_aAc)