Getting the error as the title says. Here is the traceback. I know lst[x] is causing this problem but not too sure how to solve this one. I\'ve searched google + stackoverfl
You can't index (__getitem__
) a _io.TextIOWrapper
object. What you can do is work with a list
of lines. Try this in your code:
lst = open(input("Input file name: "), "r").readlines()
Also, you aren't closing the file
object, this would be better:
with open(input("Input file name: ", "r") as lst:
print(medianStrat(lst.readlines()))
with
ensures that file get closed, see docs