Python Forum
How to deal with more than 1 input in a line - 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: How to deal with more than 1 input in a line (/thread-11611.html)



How to deal with more than 1 input in a line - mmaz67 - Jul-18-2018

Hi, can i know how to deal with line that sometimes have 1 input but sometimes have more. Is there any hint on what can i used to deal with this. I have few files, where the inputs varies.

Example:
file_a.txt
input a, b, c, d

file_b.txt
input a
input b

file_c.txt
input a,b,d,e,f,g,add,summ
I am planning to create a script that can list out the input one by one, line by line.

Example output:
out_a.txt
input a 
input b 
input c 
input d

out_b.txt
input a
input b

out_c.txt
input a
input b
input d
input e
input f
input g
input add
input summ
I am currently manage to work with line that only have one input by using if else condition:
if "input" in line:
     f0.write(line)



RE: How to deal with more than 1 input in a line - ichabod801 - Jul-18-2018

You need to do three things:
  • Get the text after the word 'input'. String indexing would work for this.
  • Split that text into a list on the comma (text.split(',')).
  • Output each word in the list using a for loop.