1def search_string_in_file(file_name, string_to_search):
2 """Search for the given string in file and return lines containing that string,
3 along with line numbers"""
4 line_number = 0
5 list_of_results = []
6 # Open the file in read only mode
7 with open(file_name, 'r') as read_obj:
8 # Read all lines in the file one by one
9 for line in read_obj:
10 # For each line, check if line contains the string
11 line_number += 1
12 if string_to_search in line:
13 # If yes, then add the line number & line as a tuple in the list
14 list_of_results.append((line_number, line.rstrip()))
15
16 # Return list of tuples containing line numbers and lines where string is found
17 return list_of_results
18