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
  Connecting to Remote Server to read contents of a file ChaitanyaSharma 1 162 May-03-2024, 07:23 AM
Last Post: Pedroski55
  PyYAML read list of int zisco 2 355 Apr-02-2024, 12:36 PM
Last Post: zisco
  append str to list in dataclass flash77 6 556 Mar-14-2024, 06:26 PM
Last Post: flash77
  Recommended way to read/create PDF file? Winfried 3 2,939 Nov-26-2023, 07:51 AM
Last Post: Pedroski55
  python Read each xlsx file and write it into csv with pipe delimiter mg24 4 1,531 Nov-09-2023, 10:56 AM
Last Post: mg24
  How to read module/class from list of strings? popular_dog 1 499 Oct-04-2023, 03:08 PM
Last Post: deanhystad
  No matter what I do I get back "List indices must be integers or slices, not list" Radical 4 1,232 Sep-24-2023, 05:03 AM
Last Post: deanhystad
  Program to find Mode of a list PythonBoy 6 1,168 Sep-12-2023, 09:31 AM
Last Post: PythonBoy
  FileNotFoundError: [WinError 2] The system cannot find the file specified NewBiee 2 1,623 Jul-31-2023, 11:42 AM
Last Post: deanhystad
  read file txt on my pc to telegram bot api Tupa 0 1,157 Jul-06-2023, 01:52 AM
Last Post: Tupa

Forum Jump:

User Panel Messages

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