Need help with reading input from stdin into array list - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: General Coding Help (https://python-forum.io/forum-8.html) +--- Thread: Need help with reading input from stdin into array list (/thread-17006.html) |
Need help with reading input from stdin into array list - Annie123 - Mar-24-2019 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() RE: Need help with reading input from stdin into array list - Yoriz - Mar-24-2019 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 RE: Need help with reading input from stdin into array list - Annie123 - Mar-24-2019 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? |