Python Forum
read a text file, find all integers, append to list
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
read a text file, find all integers, append to list
#1
Hello everyone,

I have multiple text files with a lot of lines.
Inside I have numbers separate with space or multiple spaces.
For example :

1 2 3 4 5 9
7 10 15 8 87
14 58 69 10 100

To simplify, let's say we have 3 files. I would like to do the following steps :
  1. Open the first file
  2. Read line by line and find all numbers.
  3. Append these numbers to a list of integers, but keep the same order.
  4. Then attach this list to a dictionary

  5. Do the same tasks for the 2 others files and then save the dictionary which contains the 3 lists in a text file.

Thank you for your help
Reply


Messages In This Thread
read a text file, find all integers, append to list - by oldtrafford - Aug-07-2022, 02:35 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  How to read a file as binary or hex "string" so that I can do regex search? tatahuft 3 1,014 Dec-19-2024, 11:57 AM
Last Post: snippsat
  Get an FFMpeg pass to subprocess.PIPE to treat list as text file? haihal 2 993 Nov-21-2024, 11:48 PM
Last Post: haihal
  Read TXT file in Pandas and save to Parquet zinho 2 1,210 Sep-15-2024, 06:14 PM
Last Post: zinho
  Pycharm can't read file Genericgamemaker 5 1,545 Jul-24-2024, 08:10 PM
Last Post: deanhystad
  Python is unable to read file Genericgamemaker 13 3,593 Jul-19-2024, 06:42 PM
Last Post: snippsat
  Connecting to Remote Server to read contents of a file ChaitanyaSharma 1 3,233 May-03-2024, 07:23 AM
Last Post: Pedroski55
  PyYAML read list of int zisco 2 1,617 Apr-02-2024, 12:36 PM
Last Post: zisco
  append str to list in dataclass flash77 6 3,294 Mar-14-2024, 06:26 PM
Last Post: flash77
  Recommended way to read/create PDF file? Winfried 3 4,628 Nov-26-2023, 07:51 AM
Last Post: Pedroski55
  python Read each xlsx file and write it into csv with pipe delimiter mg24 4 3,756 Nov-09-2023, 10:56 AM
Last Post: mg24

Forum Jump:

User Panel Messages

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