Read a line with -> for line in f1: Strip that line of spaces and newline and tabs using -> tmp = line.strip().split(":") if tmp contains any other weird characters ignore that line -> Print the desired output as required.