File tree Expand file tree Collapse file tree 1 file changed +18
-2
lines changed
Expand file tree Collapse file tree 1 file changed +18
-2
lines changed Original file line number Diff line number Diff line change 11import subprocess
22
33
4- def wordcount (input_file ):
5- result = subprocess .check_output (['wc' , input_file ], stderr = subprocess .STDOUT )
4+ def wordcount (input_file_path ):
5+ """
6+ This function calculates the number of lines, words, and characters in a text format file.
7+
8+ :param input_file_path: Full path to the input file
9+ :return: Result dictionary containing metadata about lines, words, and characters in the input file
10+ """
11+
12+ # Execute word count command on the input file and obtain the output
13+ result = subprocess .check_output (['wc' , input_file_path ], stderr = subprocess .STDOUT )
14+
15+ # Split the output string into lines, words, and characters
616 (lines , words , characters , _ ) = result .split ()
17+
18+ # Create metadata dictionary
719 metadata = {
820 'lines' : lines ,
921 'words' : words ,
1022 'characters' : characters
1123 }
24+
25+ # Store metadata in result dictionary
1226 result = {
1327 'metadata' : metadata
1428 }
29+
30+ # Return the result dictionary
1531 return result
You can’t perform that action at this time.
0 commit comments