def filter_index(collection, predicate=None, index=None):
 if ((index is None) and isinstance(predicate, int)):
  index = predicate
  predicate = None
 if predicate:
  collection = collection.__class__(filter(predicate, collection))
 if (index is not None):
  try:
   collection = collection[index]
  except IndexError:
   collection = None
 return collection

def filter_index ( collection , predicate = None , index = None ) : if ( ( index is None ) and isinstance ( predicate , int ) ) : index = predicate predicate = None if predicate : collection = collection . __class__ ( filter ( predicate , collection ) ) if ( index is not None ) : try : collection = collection [ index ] except IndexError : collection = None return collection
filter collection with predicate function and index .