File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ import csv
2+ import os
3+ import re
4+
5+ #Calculates the average difference between corresponding elements of two lists.
6+ def average_difference(list1, list2):
7+ if not list1 or not list2 or len(list1) != len(list2):
8+ return None
9+
10+ differences = [abs(float(x) - float(y[:-2])) for x, y in zip(list1, list2)]
11+ return sum(differences) / len(differences)
12+
13+ #Extracts a specific column from a text file and returns it as a list.
14+ def column_to_list(file_path, column_index, delimiter='|'):
15+ try:
16+ with open("output.txt", 'r') as file:
17+ column_list = []
18+ for line in file:
19+ values = line.strip().split(delimiter)
20+ if column_index < len(values):
21+ column_list.append(values[column_index])
22+ return column_list
23+ except FileNotFoundError:
24+ print(f"Error: File not found at '{file_path}'")
25+ return []
26+ except Exception as e:
27+ print(f"An error occurred: {e}")
28+ return []
29+
You can’t perform that action at this time.
0 commit comments