python 函数

1、函数初识,介绍filter内建函数
找出下列以‘ip’开头的字符串

['ip_10.2.223.5', 'ip_10.2.220.3', 'port_22', 'port_8001', 'port_80', 'ip_172.16.8.35']
_input = ['ip_10.2.223.5', 'ip_10.2.220.3', 'port_22', 'port_8001', 'port_80', 'ip_172.16.8.35']

def is_startswith_ip(item):
    return item.startswith('ip')

print filter(is_startswith_ip,_input)
输出
['ip_10.2.223.5', 'ip_10.2.220.3', 'ip_172.16.8.35']