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)