In [1]:
a = [3,2,5,6,7,10,12,14]
b = filter(lambda x:x%2==0, a)

In [2]:
b


Out[2]:
[2, 6, 10, 12, 14]

In [3]:
a = ['a', '1', '2', '3', 'python', 'c']
st = "python"
print dir(st)


['__add__', '__class__', '__contains__', '__delattr__', '__doc__', '__eq__', '__format__', '__ge__', '__getattribute__', '__getitem__', '__getnewargs__', '__getslice__', '__gt__', '__hash__', '__init__', '__le__', '__len__', '__lt__', '__mod__', '__mul__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__rmod__', '__rmul__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__', '_formatter_field_name_split', '_formatter_parser', 'capitalize', 'center', 'count', 'decode', 'encode', 'endswith', 'expandtabs', 'find', 'format', 'index', 'isalnum', 'isalpha', 'isdigit', 'islower', 'isspace', 'istitle', 'isupper', 'join', 'ljust', 'lower', 'lstrip', 'partition', 'replace', 'rfind', 'rindex', 'rjust', 'rpartition', 'rsplit', 'rstrip', 'split', 'splitlines', 'startswith', 'strip', 'swapcase', 'title', 'translate', 'upper', 'zfill']

In [4]:
print st.isdigit.__doc__


S.isdigit() -> bool

Return True if all characters in S are digits
and there is at least one character in S, False otherwise.

In [5]:
def digitidentify(s):
    return s.isdigit()

In [6]:
print digitidentify(st)


False

In [7]:
a = ['a', '1', '2', '3', 'python', 'c']
b = filter(digitidentify, a)

In [8]:
b


Out[8]:
['1', '2', '3']

In [9]:
a = [5,4,6,7,8,9]
b= reduce(lambda x,y:x*y, a)

In [10]:
b


Out[10]:
60480

In [13]:
a = {'host10': ['n1','n2', 'n4'], 'host2':['n2','n3', 'n5', 'n4'], 'host3':['n1', 'n2','n4', 'n3']}

In [14]:
a


Out[14]:
{'host10': ['n1', 'n2', 'n4'],
 'host2': ['n2', 'n3', 'n5', 'n4'],
 'host3': ['n1', 'n2', 'n4', 'n3']}

In [15]:
print dir(a)


['__class__', '__cmp__', '__contains__', '__delattr__', '__delitem__', '__doc__', '__eq__', '__format__', '__ge__', '__getattribute__', '__getitem__', '__gt__', '__hash__', '__init__', '__iter__', '__le__', '__len__', '__lt__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__setitem__', '__sizeof__', '__str__', '__subclasshook__', 'clear', 'copy', 'fromkeys', 'get', 'has_key', 'items', 'iteritems', 'iterkeys', 'itervalues', 'keys', 'pop', 'popitem', 'setdefault', 'update', 'values', 'viewitems', 'viewkeys', 'viewvalues']

In [16]:
b= a.values()

In [17]:
b


Out[17]:
[['n1', 'n2', 'n4', 'n3'], ['n2', 'n3', 'n5', 'n4'], ['n1', 'n2', 'n4']]

In [18]:
c = reduce(lambda x,y:set(x)&set(y), a.values())

In [19]:
c


Out[19]:
{'n2', 'n4'}

In [20]:
list(c)


Out[20]:
['n2', 'n4']

In [ ]: