def parse_unified_diff_output(lines):
 adds = []
 removes = []
 for line in lines:
  if ((len(line) > 2) and ((line[:3] == '+++') or (line[:3] == '---'))):
   continue
  elif ((len(line) > 1) and (line[:2] == '@@')):
   continue
  elif ((len(line) > 0) and (line[0] == '+')):
   added_line = line[1:].lstrip().rstrip()
   if (len(added_line) == 0):
    continue
   adds = (adds + [added_line])
  elif ((len(line) > 0) and (line[0] == '-')):
   removed_line = line[1:].lstrip().rstrip()
   if (len(removed_line) == 0):
    continue
   removes = (removes + [removed_line])
 return (adds, removes)

def parse_unified_diff_output ( lines ) : adds = [ ] removes = [ ] for line in lines : if ( ( len ( line ) > 2 ) and ( ( line [ : 3 ] == '+++' ) or ( line [ : 3 ] == '---' ) ) ) : continue elif ( ( len ( line ) > 1 ) and ( line [ : 2 ] == '@@' ) ) : continue elif ( ( len ( line ) > 0 ) and ( line [ 0 ] == '+' ) ) : added_line = line [ 1 : ] . lstrip ( ) . rstrip ( ) if ( len ( added_line ) == 0 ) : continue adds = ( adds + [ added_line ] ) elif ( ( len ( line ) > 0 ) and ( line [ 0 ] == '-' ) ) : removed_line = line [ 1 : ] . lstrip ( ) . rstrip ( ) if ( len ( removed_line ) == 0 ) : continue removes = ( removes + [ removed_line ] ) return ( adds , removes )
parses the unified diff output of two files returns a pair of adds and removes .