Well, there's several things to your question.
You want to get passed several files, read some values in each of them, then output the values into csv file.
It helps if you decompose your problem into several successive steps.
First, you need to know how to read the best and mutual friend in a given file. You can do that in a function:
def get_best_mutual(filename):
# some code
return (best_friend, mutual_friend)
Then, you can just iterate over all your files to write the values while you collect them:
for filename in list_of_filenames:
best_friend, mutual_friend = get_best_mutual(filename)
# write filename, best_friend, mutual_friend in output file
Writing into the file should be easy, I'll not go into the details.
The problem might be to actually get the values from the input files.
When you read a text file, you typically read it line by line. Then you can just look at your line to decide what to do: if it defines either best or mutual friend, save the definition, otherwise do nothing.
Concretely, it might look like:
def get_best_mutual(filename):
for line in open(filename): # read each line of the file
key, value = line.split(':', 1) # split the line along the first :
if key.startswith('Best'):
best_friend = value
if key.startswith('Mutual'):
mutual_friend = value
return (best_friend, mutual_friend)
Obviously, you'd have to protect a bit more the code, in case for example the line doesn't have a ':' in it, and you might also notice that the value starts with a space and ends with a '\n': you can use value.strip() to solve that. Same for the key, if a line starts with a space the code above will not recognize it.
You also need to decide what to do if a file doesn't have a best_friend, for example.