my.txt:
AAAAA -- [4, 2, 1, 2, 4, 2, 4, 4, 5, 2, 2, 1, 5, 2, 4, 3, 1, 1, 3, 3, 5]
BBB -- [5, 2, 1, 2, 4, 5, 4, 4, 1, 2, 2, 2, 4, 4, 4, 3, 1, 2, 3, 3, 2]
K -- [4, 1, 2, 1, 2, 1, 2, 5, 1, 1, 1, 1, 4, 2, 2, 1, 5, 1, 3, 4, 1]
How can I make a code that outputs this: (averages of all numbers in each string)
AAAAA,2.857142857142857
BBB,2.857142857142857
K,2.142857142857143
Note: the code has to work for any other text files contains different numbers/sizes of lists, so I can't just do something like str = "AAAAA -- [4, 2, 1, 2, 4, 2, 4, 4, 5, 2, 2, 1, 5, 2, 4, 3, 1, 1, 3, 3, 5]" and then find the average of this
the_file = "1.txt"
fileRef = open(the_file,"r")
localList_ofstrings=[]
for line in fileRef:
string = line[0:len(line)-1]
localList_ofstrings.append(string)
print(string)