Python Forum
Need help with reading input from stdin into array list
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Need help with reading input from stdin into array list
#1
I am new to Python and any help would be great to learn, I am reading an input line by line into an array list using stdin and the array list looks like this (in a single line): [[1.23, 0.26], [3.10, 0.05], [4.65, 0.30]]. I need to read this array list in the following format with just the space and no commas in it (and with separate lines):
[[1.23 0.26]
[3.10, 0.05]
[4.65, 0.30]]
Can somebody please help how this can be done?
My current code looks like this:
def main():
  data = []
  for line in sys.stdin.readlines()[1:]:
      input=list(map(float, line.split()))
      data.append(input)
print(data)

if __name__ == "__main__":
    main()
Reply


Messages In This Thread
Need help with reading input from stdin into array list - by Annie123 - Mar-24-2019, 11:44 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  difference between forms of input a list to function akbarza 6 1,022 Feb-21-2024, 08:02 PM
Last Post: bterwijn
  trouble reading string/module from excel as a list popular_dog 0 416 Oct-04-2023, 01:07 PM
Last Post: popular_dog
  user input values into list of lists tauros73 3 1,064 Dec-29-2022, 05:54 PM
Last Post: deanhystad
  When is stdin not connected to a tty, but can still be used interactively? stevendaprano 1 1,006 Sep-24-2022, 05:06 PM
Last Post: Gribouillis
  functional LEDs in an array or list? // RPi user Doczu 5 1,591 Aug-23-2022, 05:37 PM
Last Post: Yoriz
Question Change elements of array based on position of input data Cola_Reb 6 2,112 May-13-2022, 12:57 PM
Last Post: Cola_Reb
  Reading an Input File DaveG 1 1,247 Mar-27-2022, 02:08 AM
Last Post: deanhystad
  Reading list items without brackets and quotes jesse68 6 4,619 Jan-14-2022, 07:07 PM
Last Post: jesse68
  STDIN not working H84Gabor 3 3,556 Sep-06-2021, 08:10 AM
Last Post: H84Gabor
  Reading data to python: turn into list or dataframe hhchenfx 2 5,368 Jun-01-2021, 10:28 AM
Last Post: Larz60+

Forum Jump:

User Panel Messages

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