#alt1 def info_om_fil(filnavn): #antar at man splitter p? " "(mellomrom) lineNr = 0 cnt_ord = 0 cnt_char = 0 filen = open(filnavn,"r") linjene = filen.readlines() filen.close() for line in linjene: lineNr+=1 word = line.split() cnt_ord += len(word) for ord in word: cnt_char += len(ord) return [lineNr,cnt_ord,cnt_char] print(info_om_fil("test.txt")) l1 = info_om_fil("test.txt") print(l1) #alt2 def info_om_fil2(filnavn): #antar at man splitter p? " "(mellomrom) lineNr = 0 cnt_ord = 0 cnt_char = 0 filen = open(filnavn,"r") for line in filen: lineNr+=1 word = line.split() cnt_ord += len(word) for ord in word: cnt_char += len(ord) filen.close() return [lineNr,cnt_ord,cnt_char] print(info_om_fil2("test.txt"))