首页 > 其他 > 详细

寻找特定的值

时间:2017-05-06 09:31:33      阅读:371      评论:0      收藏:0      [点我收藏+]
 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)

 

寻找特定的值

原文:http://www.cnblogs.com/Bruce-yin/p/6815558.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!