Python Forum

Full Version: Need help with reading input from stdin into array list
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
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()
so you have a string
a_string = '[[1.23, 0.26], [3.10, 0.05], [4.65, 0.30]]\n'
and you want to do what with it exactly ?
Note: you are overwriting the built in function input
Thanks for the note, I have modified the name to avoid conflict with built in function.

The Input (stdin) :

1.23 0.26
3.10, 0.05
4.65, 0.30

I want to store the input into an array list without commas in separate lines like:
[[1.23 0.26]
[3.10 0.05]
[4.65 0.30]]

Is that possible to do?

Earlier I used to read this input as a csv_reader using numpy library, but without using numpy (no csv reader but instead use stdin) how can I achieve the same format?