1. 程式人生 > >尋找特定的值

尋找特定的值

print 轉換 元素 utf-8 str color items style lec

 1 #!/usr/bin/env python
 2 # -*- coding: utf-8 -*-
 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 for z in li:
10     x = str(z.strip())
11 if x.startswith(a) or x.startswith(A) and x.endswith(c): 12 print(x) 13 for a in tu: 14 s = str(a.strip()) 15 if s.startswith(a) or s.startswith(A) and s.endswith(c): 16 print(s) 17 #newdic = {} 18 for d,v in dic.items(): 19 if v.startswith(a) or v.startswith(
A) and v.endswith(c): 20 print(v) 21 #print(d,v) 22 for f in dic.values(): 23 if f.startswith(a) or f.startswith(A) and f.endswith(c): 24 print(f)

尋找特定的值