grep implemented by python