Python Forum
pulling multiple lines from a txt
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
pulling multiple lines from a txt
#4
More like this,can add more lines and they will be calculated.
lst = []
with open("number.txt") as f:
    for line in f:
        lst.append([int(i) for i in line.split()])

avg = [sum(el) / len(el) for el in lst]
print(avg)
Output:
[65.5, 53.0]
Reply


Messages In This Thread
pulling multiple lines from a txt - by IceJJFish69 - Apr-26-2021, 10:10 AM
RE: pulling multiple lines from a txt - by snippsat - Apr-26-2021, 11:14 AM
RE: pulling multiple lines from a txt - by snippsat - Apr-26-2021, 05:56 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Pulling Specifics Words/Numbers from String bigpapa 2 887 May-01-2023, 07:22 PM
Last Post: bigpapa
  Having trouble installing scikit-learn via VSC and pulling my hair out pythonturtle 1 858 Feb-07-2023, 02:23 AM
Last Post: Larz60+
  (Python) Pulling data from UA Google Analytics with more than 100k rows into csv. Stockers 0 1,379 Dec-19-2022, 11:11 PM
Last Post: Stockers
  Pulling username from Tuple pajd 21 4,064 Oct-07-2022, 01:33 PM
Last Post: pajd
  How to write the condition for deleting multiple lines? Lky 3 1,281 Jul-10-2022, 02:28 PM
Last Post: Lky
  Delete multiple lines from txt file Lky 6 2,530 Jul-10-2022, 12:09 PM
Last Post: jefsummers
  Display table field on multiple lines, 'wordwrap' 3python 0 1,872 Aug-06-2021, 08:17 PM
Last Post: 3python
  Pulling Information Out of Dictionary Griever 4 3,083 Aug-12-2020, 02:34 PM
Last Post: Griever
  Iterate 2 large text files across lines and replace lines in second file medatib531 13 6,340 Aug-10-2020, 11:01 PM
Last Post: medatib531
  print python json dump onto multiple lines lhailey 2 20,341 Mar-02-2020, 12:47 PM
Last Post: vishalhule

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020