码迷,mamicode.com
首页 > 编程语言 > 详细

python 小练习2

时间:2018-04-04 18:15:44      阅读:211      评论:0      收藏:0      [点我收藏+]

标签:pytho   turn   pen   练习   def   get   com   开头   return   

1、过滤问题

找出以ip开头的字符串
_input = [‘ip_10.2.223.5‘, ‘ip_10.2.220.3‘, ‘port_22‘, ‘port_8001‘, ‘port_80‘, ‘ip_172.16.8.35‘]

for item in _input:
    if item.startswith(‘ip‘):
        print(item)

技术分享图片

 

内建函数filter(fucn,seq)

python2:中,返回结果是一个列表
python3中:返回filter对象

 

def get_int(n):
    if isinstance(n,int):
        return True
    else:
        return False
    
_input = [1, 2, 3, "ss", "test", [1, 2]]
    
ret = []

for item in filter(get_int,_input):
    ret.append(item)
    
print(ret)

 

技术分享图片

 

python 小练习2

标签:pytho   turn   pen   练习   def   get   com   开头   return   

原文地址:https://www.cnblogs.com/hellojackyleon/p/8718215.html

踩
(0)
赞
(0)
   
举报
评论 一句话评论(0)
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!