python - Compare and Extract lines then send to new file -


We say that a file contains the following:

  Hello ==== ===== Last: Last: Sanski Last: King Last: Last George: Henry Last: IDA Bye Bye: ========= First: Paul First: First Sons: First Charles: Lincoln First: Ida Example Output Last : Paul First: Paul Last: First Conscious: First Suspicious: ida first: ida  

How to remove all matching names and push to write a script is possible Final and a new file, regardless of the first keywords in the beginning?

Say that the file is Names.txt

In Python:

  import import import OS f = open ('names.txt') line = f.readlines () last_names = first_names = row = rows to row = if: Line.startswith ('last:'): last_names.append (line [6:]) elif line.startswith ('first:'): first_names.append (line [7:]) Results = [name for name in Last_names If the name in the first_name] you want to do with the result  

Comments

Popular posts from this blog

Member with no value in F# -

java - Joda Time Interval Not returning what I expect -

c# - Showing a SelectedItem's Property -